I've read up so much on this, and can't figure out why my Player
object is losing its draw
function.
Object class:
class Object {
public:
Object(){}
Object(Object* o){
o->draw();
}
virtual void draw() { cout << "Object draw" << endl; }
};
Player class:
class Player : public Object {
public:
Player() : Object(this) {}
void draw(){ cout << "Player draw" << endl; }
};
When I run this code:
int main(){
Object o;
Player p;
}
The output is: Object draw
. I expect it to be Player draw
so the object is either not overriding or the object is getting sliced when it goes through the function.