我有以下类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