[C++-sig] trouble with virtual methods

David Abrahams david.abrahams at rcn.com
Wed Jan 30 12:37:53 CET 2002


I don't see anything wrong with it on the surface. If it were me I'd break
out the debugger at this point ;-/

HTH,
Dave

----- Original Message -----
From: "Hugo van der Merwe" <s13361562 at bach.sun.ac.za>
To: <c++-sig at python.org>
Sent: Wednesday, January 30, 2002 5:06 AM
Subject: [C++-sig] trouble with virtual methods


> I cannot track down what I'm doing wrong. Here follows code extracts
> from what I'm struggling with. If anyone can point me in the direction I
> should investigate, that would be great.
>
> Terrain.h contains:
> ------------
> class TextureFactory
> {
> public:
>   virtual GLuint GetTexture(int index,float originX,float originY,float
width,float height) = 0;
>   virtual void UnloadTexture(int index,float originX,float originY) = 0;
> };
> ------------
>
> My wrapper code contains:
> ------------
> class TextureFactory_callback : public TextureFactory {
> public:
>     TextureFactory_callback(PyObject* self) : /*TextureFactory(),*/
m_self(self) {
> cout << "here I am" << endl;
>     }
>     ~TextureFactory_callback(){ cout << "ack, I'm dead!" << endl; }
>
>     GLuint GetTexture(int index, float originX, float originY, float
width, float height) {
> return python::callback<GLuint>
>     ::call_method(m_self, "GetTexture", index, originX, originY, width,
height);
>     }
>
>     void UnloadTexture(int index, float originX, float originY) {
> return python::callback<void>::call_method(m_self, "UnloadTexture",
>    index, originX, originY);
>     }
> private:
>     PyObject* m_self;
> };
>
> void func(TextureFactory* t){ t->GetTexture(0,0,0,0,0); }
>
> BOOST_PYTHON_MODULE_INIT(demeter)
> {
>     python::module_builder this_module("demeter");
>     python::class_builder<TextureFactory,TextureFactory_callback>
> TextureFactory_class(this_module, "TextureFactory");
>     this_module.def(func, "func");
> <snip>
> }
> ------------
>
> Now in Python I do:
>
> >>> import demeter
> >>> class boo(demeter.TextureFactory):
> ...   def GetTexture(a, b, c, d, e): print "gotcha:",a,b,c,d,e
> ...
> >>> tf = boo();
> here I am
> >>> demeter.func(tf)
> Aborted
>
> And so it bombs out. I have looked at examples and documentation, but
> have not found the answer yet.
>
> (Note, libs/python/doc/overriding.html has a "struct baz_callback {"
> which I guess should be "struct baz_callback : baz {" ? I have 1.26.0)
>
> Thanks,
> Hugo
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig





More information about the Cplusplus-sig mailing list