我有以下類C++ 11別名和模板的模板
struct Abis
{
void foo() { // does something }
};
struct A
{
typedef Abis bis_type;
bis_type create() { // instanciates Abis object };
};
template<class Tbis> // typically Tbis would be Abis
struct Bbis
{
// something
};
template<class T> // typically T would be A
struct B
{
typedef Bbis<typename T::bis_type> bis_type;
bis_type create() { // instanciates Bbis object };
};
現在我想添加其他層:
template<class Tbis, template<class> class Ubis>
struct Cbis : public Ubis<Tbis>
{
void additional_method() { // does something calling Tbis and Ubis methods}
};
和具有C類實例化對象CBIS所以我可以寫這樣的事情:
C<A,B> c();
Cbis<Abis,Bbis> cbis = c.create();
cbis.additional_method();
這需要能夠參考的typedef bis_types所以我想這
template<class T, template<class> class U>
struct C
{
template<class S>
using Ubis_type = U<S>::bis_type // PROBLEM!
typedef Cbis<typename T::bis_type,Ubis_type> bis_type;
bis_type create();
}
這似乎並沒有工作,而且也不
template<class T, template<class> class U>
struct C
{
template<class S>
using Ubis_type = typename U<S>::bis_type // PROBLEM!
typedef Cbis<typename T::bis_type,Ubis_type> bis_type;
bis_type create();
}
作爲一個臨時的解決辦法,我可以通過B型作爲模板參數CBIS但是這並沒有真正尊重設計,我想了解問題是什麼。
我的語法正確嗎? (我用的XCode 7.3)
感謝
你已經關閉了錯誤的開始,你得到了甚至在走出大門:'typedef的巴士轉車站bis_type;' - 「Bbis」是不是一種類型。這是一個模板。巨大差距。當然「U
」是「一個問題!」沒有在任何地方定義的模板U.所有這些看起來都像幻想代碼,而不是真正的代碼。 –*「這似乎不工作,也沒有」*,包括錯誤消息 –
模板 //它沒有意義,因爲您根本不使用T類...... –
nosbor