0

我已经阅读了很多关于此的内容,但无法弄清楚为什么我的Player对象失去了它的draw功能。

对象类:

class Object {
    public:
        Object(){}

        Object(Object* o){
            o->draw();
        }

        virtual void draw() { cout << "Object draw" << endl; }
};

球员等级:

class Player : public Object {
    public:
        Player() : Object(this) {}

        void draw(){ cout << "Player draw" << endl; }
};

当我运行此代码时:

int main(){
    Object o;
    Player p;
}

输出是:Object draw。我希望它是Player draw这样的,对象要么不被覆盖,要么对象在通过函数时被切片。

4

0 回答 0