/////////////////////////////////////////////////////////////////////////////// // // 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_H class 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; }
继承类中的成员函数将覆盖基类中的同名函数,不论virutal不virtual,和参数是否相同,基类中的函数一律不再可见。
继承名称的掩盖
时间: 2024-10-13 04:16:23