|
From: Fernando L. <fer...@gm...> - 2010-04-12 23:29:55
|
But derivarion works fine with old Style classes.
Today i was thinking in make the whole class hierarchy with old style
ones and restrict new style to some particular aspects of the
simulator (e.g. a system container that doesn't derive from Block)
Best regards
Fernando
2010/4/12, Barry Scott <ba...@ba...>:
>
> On 10 Apr 2010, at 19:34, Fernando Libonati wrote:
>
>> In cxx_extensions.cxx
>>
>> extern "C" PyObject *getattro_handler( PyObject *self, PyObject *name )
>> {
>> try
>> {
>> PythonExtensionBase *p = getPythonExtensionBase( self );
>> return new_reference_to( p->getattro( Py::String( name ) ) );
>> }
>> catch( Py::Exception &)
>> {
>> return NULL; // indicate error
>> }
>> }
>>
>> In a derived class this always call the getattro of the base class, and
>> never get the derived class attributes visible.
>> How can I access a derived class attro?
>>
>> I've attached the test system, base.h and base.cxx.
>> When compiled, it is possible to create a g = base.Gain("b",1,None,2.43)
>> object, and access name,number and parent attributes, but doesn't reach
>> the gain attribute.
>> Python says
>> """Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> AttributeError: 'Gain' object has no attribute 'gain'
>> """
>>
>> It would be possible to call first the derived class method, and inside it
>> call the base class method (under the user responsibility)?
>
> You cannot use C++ derivation to create a set of Python types.
>
> When Block is setup there are a lot of python data structures created and
> initialise to make Block available to Python.
>
> Gain has none of these python data structures.
>
> If you want a hierarchy of classes then only the leafs can be turned into
> Python classes.
>
> Barry
>
>
> ------------------------------------------------------------------------------
> Download Intel® Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> CXX-Users mailing list
> CXX...@li...
> https://lists.sourceforge.net/lists/listinfo/cxx-users
>
--
Fernando Libonati
fernando.libonati at gmail.com
|