Re: [Boost-users] opengl and boost::function casting problems. .

________________________________________ From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of chun ping wang Sent: Tuesday, August 22, 2006 10:36 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] opengl and boost::function casting problems. . Hi, sorry for another problem... i have a simple question to ask... lets say say i have base class struct GeomObject { // draws an wire shape virtual void drawAbstract(const GLfloat& x, const GLfloat& y, const GLfloat& z) = 0; // draws a solid shape. virtual void drawSolid(const GLfloat& x, const GLfloat& y, const GLfloat& z) = 0; } Now i have bunch of stuff that inherits it.. Like class Circle, class Sphere, class Cylinder, class Cone and all of them implement drawSolid and drawAbstract (radius base assumed). I have a function call drawCircle(const std::string& r, (someBoostFunctionParam)) { Circle cir(4.0, r); // construct a circle with radius 4.0 and name r cir.someBoostFunctionParam(x, y, z); } thus if i say drawCircle("solid", &Circle::drawSolid); drawCircle("abstract", &Circle::drawAbstract); How do you do that? Or whats the best way to do it. [Nat] Since drawCircle() is specifically drawing a Circle, it would work to use an ordinary member function pointer: void drawCircle(const std::string& r, void (Circle::*drawFunction)(const GLfloat&, const GLfloat&, const GLfloat&)) { Circle cir(4.0, r); // construct a circle with radius 4.0 and name r GLfloat x = 0, y = 0, z = 0; // set values for x, y, z somehow (cir.*drawFunction)(x, y, z); } Normally I'd use typedef to tame member function pointer syntax, but it appears that you'd want a different subclass-specific member function pointer for each such drawSomething() free function.
participants (1)
-
Nat Goodspeed