Hi Mattias, The problem you have is down to two osg::Referenced objects being inherited into a single object via the multiple inheritance. The C++ solution is to make ReadFileCallback and WriteFileCallback using virtual inheritance of osg::Referenced, this should allow you to use multiple inheritance safely. I have just checked in this change to SVN.
As for general design guidelines for single vs multiple inheritance, in general single inheritance should be preferred, multiple inheritance is best kept for providing multiple interfaces. The use of object composition is also typically better than using inheritance - object composition in your case would be to have the common helper variables/methods factored out into its own class that the separate callbacks share. What is best for your app takes consideration of lots of factors, that you alone know, so you just need to figure out your options how they address the problem in hand and use a good dose of good taste to work out whats best. Robert. On 8/22/07, Mattias Linde <[EMAIL PROTECTED]> wrote: > Hi, > > I need to do some special things when some files are loaded and written so > I'm using > osgDB::Registry::{Read,Write}FileCallback - so far all good. There are some > common functionality in the code I don't want to repeat, so the callback stuff > is put into one class. > > This causes problems with osg beacuse when MyCallback inherits from both > ReadFileCallback > and WriteFileCallback there 'll be two osg::Referenced. If normal pointers > are used, one > can get the code that uses MyCallback to compile, but crashes are bound to > happen... > If ref_ptr<MyCallback> is used, the compiler find the problem. > > >From this I suggest that both osgDB::Registry::{Read,Write}FileCallback use > >virtual > inheritance from osg::Referenced. > > Or if there is any good reason not to put all the callback stuff in the same > class I'd > be happy to hear about it. > > / Mattias > > > > > > > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org