template<typename T>
class Foo {
template<???>
Foo(Container<T> c) {
}
};
...
//this can't be changed
std::vector<int> vec;
Foo<int> foo1(vec);
std::list<double> list;
Foo<double> foo2(list);
嗯?模板和STL容器
template<typename T>
class Foo {
template<???>
Foo(Container<T> c) {
}
};
...
//this can't be changed
std::vector<int> vec;
Foo<int> foo1(vec);
std::list<double> list;
Foo<double> foo2(list);
嗯?模板和STL容器
这是不是在所有我清楚你问什么。我认为你可能需要编辑你的问题,以更具体和更完整。
#include <vector>
#include <list>
template <typename T>
class Foo {
public:
template<typename T1>
Foo(T1 c) {
}
};
std::vector<int> vec;
Foo<int> foo1(vec);
std::list<double> list;
Foo<double> foo2(list);
这很难电话要实现这个东西,但下面一个简单的模板应该做的伎俩:
template <typename T>
class Foo
{
Foo(std::vector<T> const& v)
{
// initialize from vector
}
Foo(std::list<T> const& l)
{
// initialize from list
}
};
...
std::vector<int> vec;
Foo<int> foo1(vec);
std::list<double> list;
Foo<double> foo2(list);
谢谢。但是我需要对MyClass
什么:
在此之前,如果你这样做你的程序将编译就好了?为什么要求奇怪? – GManNickG 2011-04-19 21:45:10