i don't need it to be pure as i still need to use the base class version of it on other calls as i only have the base call and one derived class. The way i see my code it is working as i have taken out the derived class version and it runs the base calls version but i just having trouble understanding what the actually virtual keyword does as having it in there doesnt make any difference. But maybe i have done something wrong.
Code:
car.h
class Car {
public:
Car();
Car(int n);
string another_thing()const;
private:
int n;
};
Code:
Car.cpp
Car::another_thing() const{
cout << "something" << endl;
}
Code:
bus.h
class Roman: public Number {
public:
string get_fuel_amount()const;
private:
int n;
};
Code:
bus.cpp
Bus::another_thing() const{
Car::another_thing() const{
cout << "something different" << endl;
}
}
Code:
main.cpp
int main(){
Car one;
one.another_thing() << "\n";
Car two
two.another_thing() << "\n";
Bus three
three.another_thing() << "\n";
return 0;
};
That is my code dumbed down if there is errors in the code it doesnt matter just trying to get the concept right about the virtual. As you can see i have not set virtual, yet is always knows what type it is. I'm just to work out where and why we set it and why its not always needed but mainly to when and why i would use it.
Thanks for taking the time. much appreciated.