2014-09-25 77 views
0

非常简单,有没有任何方法可以让A引用B :: value_type,B引用A :: value_type?解决循环依赖嵌套类型说明符

struct B; 

struct A { 
    using value_type = int; 
    value_type a; 
    B::value_type b; 
}; 

struct B { 
    using value_type = int; 
    value_type b; 
    A::value_type a; 
}; 

回答

0

只能以非常冒险的方式。

template<int> struct Z 
{ 
    struct B; 

    struct A { 
     using value_type = int; 
     value_type a; 
     typename B::value_type b; 
    }; 

    struct B { 
     using value_type = int; 
     value_type b; 
     typename A::value_type a; 
    }; 
}; 

using A = Z<0>::A; 
using B = Z<0>::B; 
+0

这样做,只需要使用声明的顺序交换最后两个。我不确定它为什么会起作用。订单为什么重要? – 2014-09-25 23:29:43

+0

没关系改变顺序,编译前我一定没有保存过。 – 2014-09-25 23:59:33