[osg-users] dynamic_cast equivalent in osgDotNet

Michael Wittman wittman at acm.org
Tue Oct 2 21:20:07 PDT 2007


Hi Christophe,

I think Christoffer is trying to do a downcast of OsgGA.GUIActionAdapter
to Osg.Viewer, rather than the other way around.  Downcasts are supported
in osgDotNet, but only along the "leftmost" branch of the inheritance
tree of the runtime type.  This is a limitation of the single inheritance
model of the CLR.

osgGA::GUIActionAdapter is not on the leftmost branch of
osgViewer::Viewer's inheritance tree, so that's the reason behind the
error message.

It's possible to add support to osgDotNet for upcasts along non-leftmost
inheritance branches.  But downcasting in the same situation is a much
harder problem, and I don't know of a good solution for it at the moment.

-Mike


On Tue, Oct 02, 2007 at 01:50:27PM +0200, Christophe Medard wrote:
> That's just because what you do is strange : OsgGA.GUIActionAdapter isn' a 
> child class of  OsgViewer.Viewer.
> 
> OsgViewer.View aa;
> OsgViewer.Viewer viewer = aa as OsgViewer.Viewer;
> 
> as a valid example perfectly works.
> Not only does the 'as' cast your aa OsgViewer.View reference to an 
> OsgViewer.Viewer reference, but it also test the validity of such a cast, 
> making viewer as null is something goes wrong.
> 
> Hope that helps.
> 
> -- 
> Christophe Médard
> Société OKTAL (http://www.oktal.fr)
> 2 impasse Boudeville
> 31100 Toulouse (France)
> Tél. : (+33) 5 62 11 50 10
> Fax : (+33) 5 62 11 50 29
> 
> 
> ----- Original Message ----- 
> From: "Christoffer Markusson" <ch.markusson at gmail.com>
> To: <osg-users at lists.openscenegraph.org>
> Sent: Tuesday, October 02, 2007 1:24 PM
> Subject: Re: [osg-users] dynamic_cast equivalent in osgDotNet
> 
> 
> > Hi Christophe,
> >
> > That gives error message
> >
> > "Cannot convert type 'OsgGA.GUIActionAdapter' to 'OsgViewer.Viewer'
> > via a built-in conversion".
> >
> > Doing a direct cast, "viewer = (OsgViewer.Viewer)aa", also gives a
> > error message when compiling in Visual Studio 2005.
> >
> > Christoffer
> >
> 
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



More information about the osg-users mailing list