错误:请求会员''很暧昧

时间:2016-09-18 18:03:09

标签: c++

代码:

class A1 {};
class A2 {};

template <class M>
class Base
{
public:
  void func(M &m) const {}
};

class Derived : public Base<A1>, public Base<A2>
{};

int main()
{
  Derived d;
  A1 a1;
  d.func(a1);
}

编译错误:

AmbiguousFunction.cpp: In function \u2018int main()\u2019:
AmbiguousFunction.cpp:19: error: request for member \u2018func\u2019 is ambiguous
AmbiguousFunction.cpp:9: error: candidates are: void Base<M>::func(M&) const [with M = A2]
AmbiguousFunction.cpp:9: error:                 void Base<M>::func(M&) const [with M = A1]

为什么会出现此错误?有两种风格的功能,一种是A1,另一种是使用A2作为参数而未创建?

0 个答案:

没有答案