I have a template class called basic_posint, in which I have declared a friend function
but the compiler gives me the following error:Code:template<unsigned BASE> class base_posint : public integer { ... public: friend std::ostream& operator <<(std::ostream&, const basic_posint); }
The function is declared as public. What does it mean, doesn't it recognize basic_posint as a typename?Code:integer.hpp:85: error: ISO C++ forbids declaration of `basic_posint' with no type
Edit: I also tried your example template class, and it compiled without any warnings. On the other hand, if I replaced the function body by a semi colon (hence defining the function somewhere else), I got the following warning:
Is it supposed to be like this? Do you have to define the function within the class to prevent this warning? (I'm compiling with g++)Code:integer.hpp:48: warning: friend declaration `std::ostream& operator<<(std::ostream&, const SomeClass<T>&)' declares a non-template function integer.hpp:48: 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




Reply With Quote
