2014-09-25 41 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