[Mono-list] How to expose C++ virtual functions?

Paolo Molaro lupus@ximian.com
Fri, 17 Jan 2003 18:27:08 +0100


On 01/17/03 J. Perkins wrote:
> How do I get "base.OnInit()" to call wxApp::OnInit()? The obvious, but
> wrong, solution would be to have base:OnInit() call an unmanaged C
> function like this:
> 
>    bool _App_OnInit(wxApp* theApp) 
>    {
>       return theApp->OnInit();
>    }
> 
> But that will just end up in the _App::OnInit() virtual function again.
> I think this is the last issue I need to resolve; I am hoping that
> someone else has solved it before me.

I think the only portable way is to add a C function that will call a
C++ helper function in the derived class, The latter can call
base->method() safely, since the C++ compiler knows what to do in that
case.

This only works if you have control on the derived class and that would
mean that, if you want to override a method in a C#-defined class that
virtually derives from a class in C++ code, you need to make a helper
class and derive from that.
The Qt# folks may have found a different/better solution.

Another solution is to integrate the ability to map between the CLR
virtual table and the C++ virtual table to the mono runtime.
This would be compiler-specific (and mono-specific), but it has already
been done and it's possible the MS CLR runtime will support something
like that in the future anyway (this is just my speculation, now that
mono is catching up, they need to add some 'unique' feature to their
runtime;-).

lupus

-- 
-----------------------------------------------------------------
lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better