#include <iostream> #include <deque> #include <list> template<typename T> class Holder { public: Holder(){} template<typename I> Holder(I begin, I end) : m_data(begin,end) { } private: typedef std::deque<T> Data; Data m_data; }; int main() { std::list<int> ints; ints.push_back(3); ints.push_back(4); ints.push_back(5); // Works implicitly: Holder<int> HoldedInts(ints.begin(), ints.end()); Holder<int> *pHI_1 = new Holder<int>(ints.begin(), ints.end()); delete pHI_1; // Does not work explicitly: // Holder<int> HoldedInts<std::list<int>::const_iterator>(ints.begin(), ints.end()); // Holder<int> *pHI_1 = new Holder<int><std::list<int>::const_iterator>(ints.begin(), ints.end()); // delete pHI_1; return 0; }
2012-03-14
Invoking template constructor of a template class
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment