I'm trying to call a method from the subclass by calling a method in the super class.
Here's an example:
#include <iostream>
using namespace std;
class Robot {
public:
Robot() {
printf("Robot init\n");
update();
}
virtual void update() {
printf("Robot update\n");
}
};
class Terminator: public Robot {
public:
Terminator(): Robot() {
printf("Terminator init\n");
}
virtual void update() {
printf("Terminator update\n");
}
};
int main() {
Terminator terminator;
Robot* robot = &terminator;
}
This code returns (with annotation)
Robot init
Robot update <--- not what I want
Terminator init
How can I make it return
Robot init
Terminator update <--- what I want
Terminator init
using update
in the robot the robot constructor?