From: Patrick L. <pat...@ho...> - 2009-01-03 06:31:52
|
I am experiencing a problem when I try to overload the ostream and istream operators for a template class. I have tried to search for information on the internet and it seems like this will not be possible. However, I would like to know if you think this is possible or not. Kind regards, Patrick My class looks like: (Shortened of course) ---------CODE SNIPPET START---------- template class Stack { public: friend istream& operator>> (ostream& istream, const Stack& stack); }; template friend istream& operator>> (ostream& istream, const Stack& stack) { return istream; } ---------CODE SNIPPET END---------- And then I get the following errors. ---------COMPILE ERROR START---------- ..\stack.h:45: warning: friend declaration `std::istream& operator>>(std::ostream&, const Stack&)' declares a non-template function ..\stack.h:45: warning: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here) -Wno-non-template-friend disables this warning ..\stack.h:111: error: can't initialize friend function `operator>>' ..\stack.h:111: error: friend declaration not in class definition ---------COMPILE ERROR END---------- |