[求助]重载流运算符+模板,有编译错误
我写了几行程序,重载ostream来输出一个deque容器的内容。VC下编译不过。
#include <iostream> #include <deque> using namespace std; template< typename T > ostream& operator<<( ostream, const deque< T >& collection ) { for( auto it = collection.begin(); it != collection.end(); ++ it ) { strm << *it; } return strm; } int _tmain(int argc, _TCHAR* argv[]) { deque<int> di; di.push_back(1); di.push_back(2); cout<<di<<endl; return 0; }
#include <iostream> #include <deque> using namespace std; template< typename T > ostream& operator<<( ostream &strm, const deque< T >& collection ) { for( typename deque<T>::const_iterator it = collection.begin(); it != collection.end(); ++ it ) { strm << *it; } return strm; } int main() { deque<int> di; di.push_back(1); di.push_back(2); cout<<di<<endl; system("pause"); return 0; }