我实例化了一个模板并想将该实例用于其他模板
template <typename I> class A
{
I name;
public:
A(I n){
name = n;
}
void show() const
{
cout << name << "\t";
}
};
template <template<typename I> class V> class B {
V origen;
public:
B (V o){
origen = o;
}
};
auto main() -> int
{
cout << "[code.cpp]" << endl;
A<int> a1(1);
a1.show();
B<A> b1(a1);
return 0;
}
关于这个主题,我看到的是通常不使用,但在使用时,不以这种形式使用,我不明白为什么。 我尝试使用常量。不工作
最佳答案
V origen;
和 void B (V o)
无效,因为 V
不是类型。
也许你想要
template <typename T> class B;
template <template<typename> class V, typename T>
class B<V<T>>
{
V<T> origen;
public:
B (V<T> o) : origen(o) {}
};
然后
A<int> a1(1);
B<A<int>> b1(a1);
或者也许
template <template<typename> class V>
class B
{
V<int> origen;
public:
B (V<int> o) : origen(o) {}
};
然后
A<int> a1(1);
B<A> b1(a1);
关于c++ - C++中的模板模板参数。使用实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50457832/