By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,376 Members | 3,024 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,376 IT Pros & Developers. It's quick & easy.

Inheritance in managed c++.

P: n/a
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.

Apr 25 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.
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.


Apr 25 '07 #2

P: n/a
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

Apr 30 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.