lets say i have a base with a virtual function. when i implement that function in the derived class many examples dont use the word virtual in the derived class for that fuction. however if i add the word virtual to the derived class virtual function it seems to work the same. is there a difference ?
class test
{
public:
virtualvoid test(){}
};
class derived : public test
[
public:
// whats the difference between this and the one in the comment below
void test(){}
// what is different from
// virtual void test(){}
// in this derived class. it seems to do the same wether i
// add virtual keyword in derived class or not
};
I tested it with a more advanced example using polymorphism and you are correct. as long as the base class defined virtual it didnt matter in the derived class for the same function if it said virtual. both results compiled perfectly and printed out the exact same.