Overloading Output operator for a class template in a namespace?

You need to move your implementation of operator into the same namespace as your class. It's looking for: ostream& operator& p_t) But won't find it because of a short-coming in argument-dependent look-up (ADL). ADL means that when you call a free function, it'll look for that function in the namespaces of it's arguments.

This is the same reason we can do: std::cout int main() { N::C a10; std::accumulate( a, a+10, 0 ); // legal? Not specified by the standard } Same situation you have The book C++ Coding Standards by Sutter and & Alexandrescu has a useful guideline: Keep a type and its nonmember function interface in the same namespace Follow it and you and ADL will be happy. I recommend this book, and even if you can't get one at least read the PDF I linked above; it contains the relevant information you should need Note that after you move the operator, you'll need your friend directive (so you can access private variables): template friend ostream& operator& p_t) And ta-da!Fixed.

You need to move your implementation of operator& p_t) But won't find it because of a short-coming in argument-dependent look-up (ADL). ADL means that when you call a free function, it'll look for that function in the namespaces of it's arguments. This is the same reason we can do: std::cout int main() { N::C a10; std::accumulate( a, a+10, 0 ); // legal?

Not specified by the standard } Same situation you have. The book "C++ Coding Standards" by Sutter and & Alexandrescu has a useful guideline: Keep a type and its nonmember function interface in the same namespace. Follow it and you and ADL will be happy.

I recommend this book, and even if you can't get one at least read the PDF I linked above; it contains the relevant information you should need. Note that after you move the operator, you'll need your friend directive (so you can access private variables): template friend ostream& operator& p_t); And ta-da! Fixed.

Okay, even if the output operator is defined in global namespace and the class in skg namespace, cout – Surya Jan 29 '10 at 5:11 @Surya: Clarified. It simply can't look there. – GMan Jan 29 '10 at 5:16.

You need to move your implementation of operator Even though operator It will see possibilities (all the normal operator This is discussed in an article by Herb Sutter: "A Modest Proposal: Fixing ADL.". Same situation you have. Keep a type and its nonmember function interface in the same namespace.

Follow it and you and ADL will be happy. I recommend this book, and even if you can't get one at least read the PDF I linked above; it contains the relevant information you should need.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions