[C++-sig] Limit On No. Of Constructors?
dave at boost-consulting.com
Thu Nov 14 19:50:31 CET 2002
"Scott A. Smith" <ssmith at magnet.fsu.edu> writes:
> Hi Dave,
>> You need to either get a better compiler (even vc7 would be an
>> improvement), or split your module code across translation units
>> (source files). To do that, declare a function in another source file
>> taking a class_<SinglePar>& parameter, and move some of your .def()
>> calls there.
> In another message you wrote:
>> Split up your file into multiple translation units (separate source
>> files). Your module initialization function can call a function
>> defined in another source file to expose additional functionality.
> Ouch. It'll be a while before I can upgrade to .NET, but I am trying to
> build my modules multiplatform so I run with GCC using CygWin & Linux (& one
> perhaps even OSX).
We're looking for a workaround for this VC6 bug. Maybe Monday (but
> But for now, I am hoping you can clarify your statements
> on how to deal with the vc6 problem.
> 1.) When I declare a class:
> class_<MyClass>("MyClass", init<>())
> ... class constructors and functions
> it would seem that all .def() calls for the class must reside before
> the semi-colon used for the class end. Hence, I don't see how I can move
> of these into a separate file.
> I have no problems moving entire classes
> into individual files. I don't understand how I can use a
> parameter in a different file then continue putting in .def() calls that
> are part of the class MyClass. Could you give me a brief example?
> 2.) Is it possible to blend modules. That is, make a Python module that has
> class A, one that has class B, then somehow blend the two into a single
> module. Then only the summed moduled is imported into Python rather than
> all of the individual ones?
No, but you don't need two module definitions.
> 3.) I keep all my BP functions in separate files, except those functions
> needed to be part of a class (e.g. for weak wrapping using V1). I have
> always done this using header files, so the structure of my code is
> different from all of the tutorial examples. I am wondering if, for
> reasons, I should be keeping my BP functions in (.cpp) files instead?
> Currenty I have a single header file that contains, among other things,
> # include <FileA.h>
> # include <FileB.h>
> Is there a better, or more standardized, way of organizing my code while
> keeping what is related to BP largely away from what is my project's
> usual C++ code?
Generally speaking, #including headers into the interior of
Boost.Python module initialization functions won't work out
well. Maybe you should try:
// module file
extern void wrap1();
extern void wrap2();
... // wrapping code for header1.h
... // wrapping code for header2.h
But note: this is not a Boost.Python question, it's a C++
question. There's nothing special about file organization for
Boost.Python projects that doesn't apply to run-of-the-mill C++
(except for freaky compiler limitations like c1204). If you have more
questions about this, please consider asking them in a general C++
dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution
More information about the Cplusplus-sig