I am running into an issue where an overloaded function is not called, and the base function is called instead. I suspect this is related to how things are split between the pr
print
is not a virtual function, so you are just relying on static dispatch. This will select the function to call based on the static type of the object, which is obj1
in this case.
You should make print
virtual:
class obj1{
public:
virtual void print();
};
Then if you use C++11 you can mark obj2::print
as override
for safety's sake:
class obj2 : public obj1{
public:
void print() override;
};
Also note that you never allocate any memory for newobj2
.