opengl - Issue overriding c++ class for drawing curve -


i'm trying implement program lines drawn point point when user clicks on screen. have polyline class, subclass of freeform class, subclass of curve class. draw method of curve superclass calls getpoint, weighted point curve @ specific point. however, in case of draw method polyline, i'm trying override curve class point user clicking on (as can see, draw method of polyline class never calls getpoint). however, when debug code see getpoint still being called when try draw polyline. suggestions?

class curve {  public:     virtual float2 getpoint(float t)=0;      void draw(){          glbegin(gl_line_strip);         (float = 0; < 1; i+=.01) {             float2 point = getpoint(i);             float x = point.x;             float y = point.y;             glvertex2d(x, y);          }         glend();         };      };  class freeform : public curve { protected:     std::vector<float2> controlpoints;  public:     virtual float2 getpoint(float t)=0;     virtual void addcontrolpoint(float2 p)     {         controlpoints.push_back(p);     }     void drawcontrolpoints(){         glbegin(gl_points);         (float = 0; < controlpoints.size(); i++) {             float2 point = controlpoints.at(i);             float x = point.x;             float y = point.y;             glvertex2d(x, y);          }         glend();// draw points @ control points     } };  class polyline : public freeform { public:     float2 getpoint(float t) {         return float2(0.0, 0.0);     }     //we add control point (in case, control point mouse clicked)     void addcontrolpoint(float2 p)     {         controlpoints.push_back(p);     }     //trying override curve draw method     void draw(){         glbegin(gl_line_strip);             (float = 0; < controlpoints.size(); i++) {             float2 point = controlpoints.at(i);             float x = point.x;             float y = point.y;             glvertex2d(x, y);         }         glend();     }; }; 

//trying override curve draw method 

the comment above pretty says all; "trying" override void curve::draw (), fail since member-function not declared virtual.


solution

  • declare void curve::draw () virtual.
  • if or later, (and make use of) keyword override.

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -