I am just testing with virtual keyword and inheritance concepts in c++. I have written a small program:
#include
#include
us
That can't work because given a cna_MO *
, you can see at compile-time that the pointed object does not (necessarily) have the int overload. If it actually pointed to a base-class object, _mo->print(5);
would really have nothing to call. Also there can be an infinite number of (not yet implemented) derived classes that don't have to support this call.
Every derived class must have print(int)
- declare it in the base class.
Every derived class need not have print(int)
- cna_Mo
only works with cna_bsc
, so the member should be cna_bsc* _mo
.