#include <iostream>
using namespace std;
class base
{
public:
void f() {cout << "base" << endl;}
virtual void v() {cout << "base (virtual)" << endl;}
};
class deriv : public base
{
public:
void f() {cout << "deriv" << endl;}
void v() {cout << "deriv (overridden)" << endl;}
};
int main()
{
base b;
b.f();
b.v();
deriv d;
d.f();
d.v();
}
I don't understand what real difference is there between those two methods f and v: if I replace a function with another with the same name, am I not "replacing" it ? Even if I can still access it by creating a base* pointer and then make it point to a deriv object, I don't understand what kind of "clean" use of C++ there is here.
When not using virtual (meaning overriddable methods) methods, can somebody tell me if there is a legitimate use for this, and what is different from using overridden virtual method ?
EDIT: I'm sorry using bad syntax with markdown, but markdown is a really bad choice, it's complicated and quite capricious (I prefer textile hehe). EDIT2: Sorry I didn't guess 101010101010101 button meant to insert code, I usually just do it by hand :(