I am just testing with virtual keyword and inheritance concepts in c++. I have written a small program:
#include
#include
us
Ideally your print that takes an int should have a different name but given you want both functions to be called print, you should make them both non-virtual and make them call protected virtual functions.
class cna_MO
{
public:
void print() { doPrint(); }
protected:
virtual void doPrint()
{ cout << "cna_MO" << endl;
}
};
class cna_bsc:public cna_MO
{
protected:
virtual void doPrint()
// although with implementation no need to override it
{
cna_MO::print();
}
public:
void print(int a)
{
doPrintInt( a );
}
protected:
virtual void doPrintInt( int )
{
cout << "cna_BSC" << endl;
}
};