c++ template question:# Programming - 葵花宝典
F*i
1 楼
I am trying to test a template function to print out all
the elements of stl containers:
template class T > void print( const T > & coll )
{
copy (coll.begin(), coll.end(), // source
ostream_iterator(cout," ")); // destination
cout << endl;
}
list coll;
// insert elements from 6 to 1 and 1 to 6
for (int i=1; i<=6; ++i) {
coll.push_front(i);
coll.push_back(i);
}
print >(coll); /
the elements of stl containers:
template
{
copy (coll.begin(), coll.end(), // source
ostream_iterator
cout << endl;
}
list
// insert elements from 6 to 1 and 1 to 6
for (int i=1; i<=6; ++i) {
coll.push_front(i);
coll.push_back(i);
}