[C++-sig] Limit On No. Of Constructors?
gideon may
gideon at computer.org
Thu Nov 14 19:50:10 CET 2002
I am not Dave ;)
but I've come across the same problem.
--On Thursday, November 14, 2002 10:48 AM -0500 "Scott A. Smith"
<ssmith at magnet.fsu.edu> wrote:
> Hi Dave,
>
> perhaps even OSX). 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 any
> 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
> class_<MyClass>&
> 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?
The def method of class_ returns a reference to the class object. This
allows
chaining of the method calls.
To split the def calls over multiple functions you can do something like :
void second_definition(class_<MyClass> & my_class)
{
my_class
.def("method2", &MyClass::method2)
;
}
void first_definition()
{
class_<MyClass> my_class("MyClass")
.def("method1", &MyClass::method1)
;
}
> 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?
>
> 3.) I keep all my BP functions in separate files, except those functions
> that
> 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
> quite
> different from all of the tutorial examples. I am wondering if, for
> whatever
> reasons, I should be keeping my BP functions in (.cpp) files instead?
> Currenty I have a single header file that contains, among other
> things,
>
> BOOST_PYTHON_MODULE(MyModule)
> {
># 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?
Why not something like this :
FileA_impl.cpp ====================================
#include <FileA.h>
void ClassA_impl()
{
class_<ClassA> class_a("ClassA")
.
.
.
}
FileB_impl.cpp =====================================
#include <FileB.h>
void ClassB_impl()
{
class_<ClassB> class_b("ClassB")
.
.
.
}
FileWrapper.cpp ===============================
void ClassA_impl();
void ClassB_impl();
BOOST_PYTHON_MODULE(MyModule)
{
ClassA_impl();
ClassB_impl();
}
--------------------------------------------
This way you have a nice separation between the
class wrapper implementations.
HTH
gideon
More information about the Cplusplus-sig
mailing list