[C++-sig] Polymorphism with injected constructor...

Alex Mohr amohr at pixar.com
Thu Jan 5 22:07:53 CET 2006


> Did you try adding a constructor to the Derived class
> that explicitely calls Base.__init__ ?

Actually I tried doing this:

class Derived(Base):
	def __init__(self):
		Base.__init__(self)
	def Func(self):
		return 'Python Func'

But that didn't make any difference so I left it out for brevity.

> I'm not sure I completely understand the python object model,
> in particular, the relationship between classes and their
> base classes as far as object layout is concerned, but
> I would imagine that a function returning a new base class
> instance can't really be used to initialize a base class
> of a derived instance. Just a guess...

Hmm... I guess I'm not sure what's really different about the case of an 
injected constructor versus not.  The wrapper object is getting 
constructed properly -- it's just not able to find the python override 
for Func.

Thanks,

Alex



More information about the Cplusplus-sig mailing list