Given the following code:
class Base {
public:
virtual void Test() {
cout << "Not Overridden" << endl;
}
};
class Derived : public Base {
public:
void Test() override {
cout << "Overridden" << endl;
}
};
int main() {
Base o = Derived();
o.Test();
return 0;
}
Someone like me who is from a Java background, expects the compiler to output Overridden
but surprisingly the output is exactly the otherwise.
If this is a normal behavior, then what's the point of inheritance in C++ at all?
What is that I am missing?