钻石继承与提升::绑定
Diamond inheritance with boost::bind
我有这样的设计:
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 调用。在 C 和 D 中调用函数没有问题。这是确切的错误:
boost/bind/mem_fn_template.hpp(384):错误 C2594:"换行符":从"具体 *"转换不明确到"A *" 跟 [ T=混凝土 ]
任何想法这可能有什么问题?
您的继承图如下所示:
Concrete
|
D
/
C B
/
A A
当您尝试将Concrete*
转换为A*
时,编译器不知道您想要哪个A
实例。是否要转换为C
派生自的A
或B
派生自的A
?
解决方案是使用虚拟继承从A
派生B
和C
,这样A
只有一个实例。
Concrete
|
D
/
C B
/
A
相关文章:
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 在基于范围的for循环中使用结构化绑定声明
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- 在使用GPU支持编译Tensorflow时,会遇到CUDA_TOOLKIT_PATH未绑定变量
- 视觉studo 2019中的漫画和静态/动态绑定
- 将自由函数绑定为类成员函数
- 将常量指针引用绑定到非常量指针
- 在派生类中绑定非静态模板化成员函数
- 绑定派生类方法C++从实例范围之外的分隔 std::function 变量调用
- 在 openGL 中多次绑定缓冲区
- 定义有趣的宏和正则表达式在Z3 C++绑定
- 使用结构化绑定'Reflection'
- 为什么 std::绑定错误参数可以成功?
- 结构绑定:与公共数据成员(继承的基类)结合
- 运行时动态绑定和类继承之间的区别
- 运行时绑定和虚拟继承
- 钻石继承与提升::绑定
- C++具有虚拟继承的重载方法绑定
- 如何使用动态绑定继承适当的类