考虑以下使用的模板,模板参数...如何申报/定义模板与模板参数的一类,而无需使用额外的模板参数
#include <iostream>
template <typename X>
class A
{
X _t;
public:
A(X t)
:_t(t)
{
}
X GetValue()
{
return _t;
}
};
template <typename T, template <typename T> class C >
class B
{
C<T> _c;
public:
B(T t)
:_c(t)
{
}
T GetValue()
{
return _c.GetValue();
}
};
using namespace std;
int main()
{
B<int, A> b(10);
cout<<b.GetValue();
return 0;
}
有没有一种方法,通过该模板参数T可以去掉?例如,是否有办法做以下工作?
//Does not compile
template <template <typename T> class C >
class B
{
C _c;
public:
B(T t)
:_c(t)
{
}
T GetValue()
{
return _c.GetValue();
}
};
int main()
{
B< A<int> > b(10);
cout<<b.GetValue();
return 0;
}
感谢您的回答,尽管我最终自己发现了这个。我正在编辑问题并发布我的工作,但显然我来到正确的地方问这个问题! – 2008-11-24 14:05:07
请注意,阳光的答案比我的好,因为他已经明白你想要什么。无需像我向你展示的那样重新绑定。只有在您使用A时才需要此功能,但偶尔会有需要或A 。或者如果用户的视图是A ,但是您使用A 。 –
2008-11-24 14:14:33