This code compiles and executes fine in Visual Studio. However, g++ gives me the error messages:
What am I doing wrong?Code:t5.cpp: In function `std::ostream& operator<<(std::ostream&, Foo<T>&) [with T = int]': t5.cpp:19: instantiated from here t5.cpp:5: `int Foo<int>::t' is private t5.cpp:14: within this context
Code:#include <iostream> template<class T> class Foo { T t; public: Foo(T tt) : t(tt) { } template<class U> friend std::ostream& operator<<(std::ostream& os, Foo<T>& f); }; template<class T> std::ostream& operator<<(std::ostream& os, Foo<T>& f) { return os << f.t; } int main() { Foo<int> f(0); std::cout << f; std::cin.get(); return 0; }



LinkBack URL
About LinkBacks



CornedBee