Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Element {
- public:
- virtual void foo() = 0;
- virtual void bar() {}
- };
- class Point : Element {
- private:
- vector<float> coords;
- public:
- virtual void foo();
- };
- class Quad : Element {
- private:
- vector<Point> points;
- public:
- virtual void foo();
- };
- /*
- How does one call a function in a derived class using a pointer to the
- base class ... where it doesn't make sense to add the function (set_coords())
- to the base (i.e., I don't make it virtual because only the Point class
- needs set_coords()).
- */
- auto elem = ElementFactory::instance()->create("Point");
- elem->set_coords(v);
- /*
- The above would complain that class Element has no member named set_coords(v);
- */
Advertisement
Add Comment
Please, Sign In to add comment