[C++-sig] Wrapping a class whose constructor takes a pointer to an abstract class
Jean-Sébastien Guay
jean-sebastien.guay at cm-labs.com
Sat Sep 20 06:24:14 CEST 2008
Hi all,
I've just started trying to use boost.python on a personal project of
mine, and I decided to start with the hardest part :-) I'm trying to
wrap OpenSceneGraph... It's going really well for the most part, and I
do mean really well. In little time I've got a good number of classes
working and tested. But I've hit a roadblock.
I've done a lot of searching and have found lots of posts on this list
dealing with pure virtual methods, but never anything about a method
taking a pointer to an abstract class as a parameter.
I have to wrap the following structure:
class osg::Shape : public osg::Object
{
// has some pure virtual methods, none of which I need to
// expose to python at this point
};
class osg::Sphere : public osg::Shape
{
// fully concrete
};
class osg::ShapeDrawable
{
ShapeDrawable(osg::Shape*, TessellationHints) { /* ... */ }
};
So the constructor to ShapeDrawable takes a pointer to the abstract base
class. My attempt to wrap this (leaving out some details) is:
// Abstract class, so noncopyable and no_init.
class_<Shape, bases<Object>, ref_ptr<Shape>,
boost::noncopyable >("Shape", no_init);
// Concrete derived class.
class_<Sphere, bases<Shape>, ref_ptr<Sphere> >("Sphere");
// Details of this class not important for now.
class_<TessellationHints, bases<Object>,
ref_ptr<TessellationHints> >("TessellationHints");
class_<ShapeDrawable, bases<Drawable>,
ref_ptr<ShapeDrawable> >("ShapeDrawable")
.def(init<Shape, TessellationHints>())
;
The first three classes wrap correctly, but the fourth fails with a
compiler error saying it cannot instantiate abstract class Shape. OK, I
understand that, but what can I do about it?
Thanks in advance for any help,
J-S
--
______________________________________________________
Jean-Sebastien Guay jean-sebastien.guay at cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/
More information about the Cplusplus-sig
mailing list