[C++-sig] shared_ptr, abstract classes and inheritance

Roman Yakovenko roman.yakovenko at gmail.com
Tue Oct 24 22:51:04 CEST 2006


On 10/24/06, Tobias Kräntzer <info at tobias-kraentzer.de> wrote:
> Am Dienstag, 24. Oktober 2006 22:15 schrieb Roman Yakovenko:
> > You did not describe the problem you actually have.
>
> sorry ;-)
>
> if i call the factory i only get the base interface not the derived.
>
> >>> import test
> >>> test.Base.create( False )
> <test.Base object at 0xb7d55df4>
> >>> test.Base.create( True )
> <test.Base object at 0xb7d55e2c>
> >>>
> >>> d = test.Base.create( True )
> >>> d.bar()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AttributeError: 'Base' object has no attribute 'bar'
> >>> d.__class__ = test.Derived
> >>> d
> <test.Derived object at 0xb7d55df4>
> >>> d.bar()
> 'Derived bar'

Try to add
implicitly_convertible< Derived::Ptr, Base::Ptr >();

Does it help?

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list