Inheritance in managed c++.

  • Thread starter Thread starter A n g l e r
  • Start date Start date
A

A n g l e r

Hello everybody. I've got a bizarre problem concerning inheritance of
the managed c++ code when using templates. Consider the following
wrapper for the unmanaged c++ class:



template <typename SomeType>

public ref class SomeManagedClass

{

private:

SomeType* pSomeObj;

public:

SomeManagedClass(void) { pSomeObj=new SomeType(); }

~EyeTouchProcBaseManaged(void) { SAFE_DELETE(pSomeObj); }

void Method1(void) { pSomeObj->Method1(); }

}



Now let's derive a new managed wrapper that specializes it a bit
further:

public ref class SomeManagedClassDer : public SomeManagedClass<SomeType>

{

public:

SomeManagedClassDer(void) : SomeManagedClass() { };

};



When using an object of the derived class SomeManagedClassDer in c# I
cannot access the Method1 method (according c#, it does not contain the
definition - although it's expected to be inherited). Does anyone know
why?! If the template is removed from the above example and replaced
with SomeType, suddenly the Method1 method becomes visible in c# scope.



Kind regards,

Peter.
 
It seems also that declaring the all methods within the base class as
virtual helps. Suddenly they are visible in c# scope, though it is still
not clear to me, why and what happens here. Cannot see the reason to
keep all methods declared as virtual.
 
It seems also that declaring the all methods within the base class as
virtual helps. Suddenly they are visible in c# scope, though it is
still not clear to me, why and what happens here. Cannot see the
reason to keep all methods declared as virtual.

Hmm. Is that such a difficult question for the professionals here or
just scarcely self-explanatory question posed by me? :)


Thx
 
Back
Top