C++ abstract class without pure virtual functions?

前端 未结 3 543
Happy的楠姐
Happy的楠姐 2020-12-01 15:44

I have a base class

class ShapeF
{
public:
    ShapeF();
    virtual ~ShapeF();

    inline void SetPosition(const Vector2& inPosition) { mPosition.Set(i         


        
3条回答
  •  情话喂你
    2020-12-01 16:25

    You could declare, and implement, a pure virtual destructor:

    class ShapeF
    {
    public:
        virtual ~ShapeF() = 0;
        ...
    };
    
    ShapeF::~ShapeF() {}
    

    It's a tiny step from what you already have, and will prevent ShapeF from being instantiated directly. The derived classes won't need to change.

提交回复
热议问题