Loo*_*oom 7 c++ templates circular-dependency crtp incomplete-type
我在模板化的类中遇到了循环依赖的问题.有一个代码示例:
template <typename T> struct A
{
typedef typename T::C D;
//typename T::C c;
};
struct B : public A<B>
{
struct C {};
};
Run Code Online (Sandbox Code Playgroud)
当我尝试实例化B时,我得到一个编译器错误:'C'不是'B'(MSVC)的成员或 无效使用不完整类型'struct B'(GCC).
更改样本以使其工作的最佳方法是什么?
struct B_base { struct C {}; };
strucr B : A<B_base>, B_base { };
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
233 次 |
| 最近记录: |