多重担任, 假如基类(base class)的成员函数名称沟通,重载(overload)函数挪用, 会忽略public和private, 选取最佳的匹配函数,
匹配度沟通, 则会造成歧义, 产堕落误:request for member ‘xxx’ is ambiguous, (GCC)
如需利用, 可以添加详细的域操纵符, 指定类("class::method()").
代码如下:
/* * test.cpp * * Created on: 2014.04.14 * Author: Spike */ /*eclipse cdt, gcc 4.8.1*/ #include <iostream> #include <string> using namespace std; class BorrowableItem { public: //共有 void checkout() { std::cout << "BorrowableItem" << std::endl; } }; class ElectronicGadget { private: //私有 bool checkout() const { return true; }; }; class MP3Player: public BorrowableItem, public ElectronicGadget {}; int main() { MP3Player mp; mp.BorrowableItem::checkout(); //不添加域操纵符会发生歧义 return 0; }
输出:
BorrowableItem
作者:csdn博客 Spike_King