[C++-sig] Re: Making copy of function derived from C++ pure virtual function
David Abrahams
dave at boost-consulting.com
Sat Dec 11 21:34:15 CET 2004
Paul F. Kunz wrote:
>>>>>> On Sat, 11 Dec 2004 09:40:20 -0500, David Abrahams
>>>>>> <dave at boost-consulting.com> said:
>
>> Sufficiently for whom? It took me 20 minutes of massaging just to
>> get it to build under vc7.1 (where I have good debugging tools).
>
> Sorry, I wasn't think about VC++
>
>> Please reduce your problem to a *simple* test case with as few
>> classes and functions as possible. Take out any threading-related
>> stuff. There should be one .cpp file and one .py file. Ideally,
>> you'd pass me a Jamfile, but I can produce one myself if
>> neccessary.
>
> Ok, one file, one Python script. No includes other that C++
> standard library.
>
> ftp://ftp.slac.stanford.edu/users/pfkeb/abrahams/HippoDraw-1.12.7.tar.gz
I'm not surprised by the behavior of this example.
You wrapped a class with a single constructor:
class_ < FunctionWrap, std::auto_ptr < FunctionWrap > >
( "FunctionBase", init < const FunctionBase & > () )
;
That constructor takes a single FunctionBase& parameter. Leaving out
the irrelevant Python code, you derive a class:
from hippo import FunctionBase
class Linear ( FunctionBase ) :
def __init__ ( self ) :
FunctionBase.__init__(self)
But this is how you call a nullary (zero-argument) ctor on a base class!
Don't try
FunctionBase.__init__(self, self)
it won't work. There's no C++ FunctionBase object yet that can be
extracted from the 2nd argument. You just need to add a Default ctor to
FunctionWrap and expose it. You also need to get rid of
FunctionWrap(PyObject*) -- that's old-style polymorphism.
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
More information about the Cplusplus-sig
mailing list