When a class inherits another publicly, then shouldn't all virtual functions get rewritten? Consider the code --
class A {
private:
vector<int> v;
public
virtual int something() {
cout << "A" << endl;
return v.size();
}
}
class B : public A {
private:
priority_queue<int> v;
public
int something() {
cout << "B" << endl;
return v.size();
}
}
Now, when I call the function something()
on an object b
of class B
by executing the statement b.something()
, I get the output A
. Why is this?