I recently came to know that in C++ pure virtual functions can optionally have a body.
I know that the body of the virtual function exist because I want to call her from the derived class, but can I do this?
class Base{
int x;
public:
virtual void print()=0;
};
void Base::print(){
cout << x;
}
class Derived : public Base{
int y;
public:
void print(){
Base::print();
cout << y;
}
};
And the result will be: the value of x and then the value of y?
What I really mean that the function Base::print() will know to get the value of x from function in the Derived class????