[C++-sig] Re: Making copy of function derived from C++ pure virtual function
David Abrahams
dave at boost-consulting.com
Tue Dec 14 21:40:10 CET 2004
Paul F. Kunz wrote:
> I replaced the file
>
> ftp://ftp.slac.stanford.edu/users/pfkeb/abrahams/HippoDraw-1.12.7.tar.gz
>
> With one that illustrates the clone() problem. One file, one script,
> no threads.
Paul, I've take a look, but you really could make my life easier. I
don't need makefiles or (worse) autoconf ".in" files. I don't need
subdirectories. I just want a .cpp (not .cxx, if we're going to pick
nits) and a .py file. You could strip out all the extraneous macros too.
Traceback (most recent call last):
File "c:\boost\libs\python\user\hippo/fitting.py", line 32, in ?
f.test()
TypeError: __init__() takes exactly 1 argument (2 given)
[5611 refs]
So your problem is really simple. In cloning the Linear object you've
created, its __init__ method is getting called with *another* Linear
object that should be the source of the clone operation. But your
Linear's __init__ function only takes one argument, as the error message
says.
If you want to pass through both default construction and copy
construction, you have to write something like:
def __init__ ( self, other = None ):
if other:
FunctionBase.__init__(self, other)
else:
FunctionBase.__init__(self)
But then, this is boring; why don't you leave off the __init__ function
altogether? Then the one(s) supplied by FunctionBase will get called.
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
More information about the Cplusplus-sig
mailing list