Boost logo

Boost Users :

From: Nat Goodspeed (ngoodspeed_at_[hidden])
Date: 2006-08-23 07:59:34


________________________________________
From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of chun ping wang
Sent: Tuesday, August 22, 2006 10:36 PM
To: boost-users_at_[hidden]
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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net