[DISABLE, INFORMATION , WARNING, ERROR]
The 'virtual' keyword is needed only in the base class's declaration of the function; any subsequent declarations in derived classes are virtual by default.
class A{ //base class
public:
virtual void f(void){ glob=2; } //definition of a
//virtual function
};
class B : public A{ //derived class
public:
void f(void){ glob=3; } //overriding function
//IMPLICIT VIRTUAL FUNCTION
};
class A{ // base class
public:
virtual void f(void){ glob=2; } //definition of a
//virtual function.
};
class B : public A{ //derived class
public:
virtual void f(void){ glob=3; } //overriding function:
//'virtual' is not
// necessary here
};
class A{ //base class
public:
virtual void f(void){ glob=2; } //definition of a
//virtual function.
};
class B : public A { //derived class
public:
void f(int a){ glob=3+a; } // not overriding function
};
A derived class's version of a virtual function must have the same parameter list and return type as those of the base class. If these are different, the function is not considered a redefinition of the virtual function. A redefined virtual function cannot differ from the original only by the return type.