C++ Overridden method not getting called

后端 未结 8 1348
逝去的感伤
逝去的感伤 2021-02-13 11:20

Shape.h

namespace Graphics {
    class Shape {
    public:
        virtual void Render(Point point) {};
    };
}

Rect.h

namespa         


        
8条回答
  •  不思量自难忘°
    2021-02-13 11:50

    This problem is called slicing - you lose the derived functionality when copying to a base. To avoid this use pointers to the base class, i.e.

    std::vector s;
    s.push_back(&some_rect);
    

提交回复
热议问题