// TemplateDemo.cpp #include <iostream> using namespace std; template <class T> class bag { int size_; public: bag(int size) : size_(size) {}; virtual ~bag() {}; template <class U> friend ostream& operator<< (ostream& os, bag<U>& b); }; template <class T> ostream& operator<< (ostream& os, bag<T>& b) { return os << "teste: " << b. size_; } template <> ostream& operator<<<int>(ostream& os, bag<int>& b) { return os << "int: " << b. size_; } int main() { bag<int> b(10); cout << b; }