我有这样的设计:

template <class T>
class A
{
};

template <class T>
class B : public A<T> 
{
};

template <class T>
class C : public A<T> 
{
};

template <class T>
class D : public C<T>, public B<T> 
{
};

struct TConcrete {
int xyz;
};

class Concrete : public D<TConcrete>
{
void Foo();
};

void
Concrete::Foo()
{
Bar (boost::bind(&A::Afunc, this, _1, _2), boost::bind(&C::Cfunc, this, _1, _2),     boost::bind(&D::Dfunc, this, _1, _2));
}

编译器抱怨第一个boost :: bind call。 C和D内部功能的呼叫没有问题。这是确切的错误:

boost/bind/mem_fn_template.hpp(384):错误c2594:'newline':从'Concrete *'到'a *'的模棱两可的转换使用[t = tconcrete

有什么想法,这有什么问题?

有帮助吗?

解决方案

您的继承图看起来像这样:

           Concrete 
              |
              D
             / \
            C   B
           /     \
          A       A

当您尝试转换您的 Concrete* 进入 A*, ,编译器不知道哪个实例 A 你要。你想转换为 AC 源自或 AB 源自于?

解决方案是使用虚拟继承来得出 BCA, ,因此只有一个实例 A.

           Concrete 
              |
              D
             / \
            C   B
             \ /
              A
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top