[C++-sig] Newcomer - constructors not working as I'd expect

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Mon Apr 10 06:26:43 CEST 2006


General remark: use valgrind you have memory problems: http://valgrind.org/

It is really easy, except that you need a suppression file for Python 2.4 or
higher: Python-2.4*/Misc/valgrind-python.supp

Then: valgrind --tool=memcheck --suppressions=valgrind-python.supp python
script.py

--- Andrew Pontzen <app26 at ast.cam.ac.uk> wrote:

>      test3(const test1 &basedon) : ourobj(basedon) { };
> ...
>      class_<test3, bases<test2> >("test3",init<test1>());
>    }

This doesn't match. I'd try: init<const test1&>()

Even if this helps I'd be really worried. If you call methods of test3 after
the test1 instance was destroyed you'll get a crash. I'd consider using
boost::shared_ptr<test1> as a member of test3. If that's not an option a call
policy may be the way to achieve safety, but I am not sure since I avoid this
kind ...

>     const test1 & ourobj;

of unsafe C++, except in very low-level code with no direct connection to the
Python layer.

Cheers,
        Ralf


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Cplusplus-sig mailing list