Boost logo

Boost :

From: VesselinPeev_at_[hidden]
Date: 2001-07-29 16:23:39


Dear Sirs,

I have come across the following problem:

class A {
        public:
                A();
                A(int i);
                virtual Func();
};

A::A()
{ printf("\nwrong (default) A constructor invoked"); }

A::A(int i)
{ printf("\nproper A constructor invoked"); }

A::Func()
{ printf("\nA function invoked"); }

class B : public A {
        public:
                B();
                B(int i);
                Func();
};

B::Func()
{ printf("\nB function invoked"); }

B::B() { printf("\nwrong (default) B constructor invoked"); }

B::B(int i) : A(i) { printf("\nproper B constructor invoked"); }

...

python::class_builder<A> aclass(qsm, "aclass");
python::class_builder<B> bclass(qsm, "bclass");
bclass.def(python::constructor<int>());
bclass.declare_base(aclass);

...

From Python script:

b = bclass(999)

Output (surprisingly for me):

wrong (default) A constructor invoked
wrong (default) B constructor invoked

Why is this happening? I am also forced to define the default
constructors without arguments, othewise I get compile errors.

One last question. Is there a good technique for specifying default
arguments of C++ functions called from Python in this way? Perhaps
through metaprogramming?

I am using Visual C++ SP6 with Win2K SP2.

Thank you in advance for you help.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk