/////////////////////////////////////////////////////////////////////////////////// FileName : effect_item33.h// Version : 0.10// Author : Ryan Han// Date : 2013/07/26 16:50:14// Comment : /////////////////////////////////////////////////////////////////////////////////#ifndef EFFECT_ITEM33_H#define EFFECT_ITEM33_Hclass base{public: virtual void mf1() = 0; virtual void mf1(int); virtual void mf2(); void mf3(); void mf3(double);private: int x;};class derive : public base {public: using base::mf1; void mf1(); void mf4();private: int y;};#endif
/////////////////////////////////////////////////////////////////////////////////// FileName : effect_item33.cpp// Version : 0.10// Author : Ryan Han// Date : 2013/07/26 16:50:14// Comment : /////////////////////////////////////////////////////////////////////////////////#include "effect_item33.h"#include <iostream>using namespace std;void base::mf1() { cout << "base::mf1() was called." << endl;}void base::mf1(int) { cout << "base::mf1(int) was called." << endl;}void base::mf2() { cout << "base::mf2() was called." << endl;}void base::mf3() { cout << "base::mf3() was called." << endl;}void base::mf3(double) { cout << "base::mf3(double) was called." << endl;}void derive::mf1() { cout << "derive::mf1() was called." << endl;}void derive::mf4() { cout << "derive::mf4() was called." << endl;}
/////////////////////////////////////////////////////////////////////////////////// FileName : effect_item33_client.cpp// Version : 0.10// Author : Ryan Han// Date : 2013/07/26 16:50:14// Comment : // Output :// $ ./a///////////////////////////////////////////////////////////////////////////////#include "effect_item33.h"#include <iostream>using namespace std;int main() { derive d; d.mf1(); d.mf1(3); return 0;}
The member functions in the inheritance class overwrite the functions of the same name in the base class. Functions in the base class are invisible no matter whether virutal is not virtual or the parameters are the same.