C++ Overridden method not getting called

后端 未结 8 1349
逝去的感伤
逝去的感伤 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:45

    No, it is not casting.

    You can instead store a reference to baseclass Point:

    struct ShapePointPair {
            Shape shape;
            Point &location;
    };
    

    This reference must be set at construction time for struct ShapePointPair. Add a constructor to ShapePointPair for this purpose. It must be passed (newly created) instances of Rect.

    Also observe the memory management responsiblities (proper written destructors, etc.).

提交回复
热议问题