gol*_*ean 40 c++ multiple-inheritance
我有一个与C++中的多继承相关的基本问题.如果我有如下所示的代码:
struct base1 {
void start() { cout << "Inside base1"; }
};
struct base2 {
void start() { cout << "Inside base2"; }
};
struct derived : base1, base2 { };
int main() {
derived a;
a.start();
}
Run Code Online (Sandbox Code Playgroud)
这给出了以下编译错误:
1>c:\mytest.cpp(41): error C2385: ambiguous access of 'start'
1> could be the 'start' in base 'base1'
1> or could be the 'start' in base 'base2'
Run Code Online (Sandbox Code Playgroud)
有没有办法能够start()使用派生类对象从特定基类调用函数?
我现在不知道用例但是..仍然!
das*_*ndy 80
a.base1::start();
a.base2::start();
Run Code Online (Sandbox Code Playgroud)
或者如果你想特别使用一个
class derived:public base1,public base2
{
public:
using base1::start;
};
Run Code Online (Sandbox Code Playgroud)