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