What to do with friend functions of a class under template?
What to do with friend functions of a class under template?
easiest way is to define the friend function within the template
to use the canonical example of op <<
of course, this isn't really cool if you want to use the same friend function for multiple templates.Code:template <typename T> class SomeTemplate { private: T m_t; public: // some methods friend std::ostream &operator>>(std::ostream &os, const SomeTemplate<T> &inst) { os >> inst.m_t; return os; } };
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?
What's the difference between a friend function declared within the class and one declared outside the class?