CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #7
    Join Date
    Jul 2007
    Posts
    17

    Re: Template stream operator overloading

    I have a template class called basic_posint, in which I have declared a friend function

    Code:
    template<unsigned BASE>
    class base_posint : public integer {
        ...
    public:
        friend std::ostream& operator <<(std::ostream&, const basic_posint);
    }
    but the compiler gives me the following error:

    Code:
    integer.hpp:85: error: ISO C++ forbids declaration of `basic_posint' with no type
    The function is declared as public. What does it mean, doesn't it recognize basic_posint as a typename?

    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:

    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
    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++)
    Last edited by TriKri; November 1st, 2009 at 06:20 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured