operator<< template error
Results 1 to 2 of 2

Thread: operator<< template error

  1. #1
    Join Date
    Sep 2003

    operator<< template error

    Hello everybody out there I have a little problem while overloading the <<operator for a class Im doing (named Set) which uses templates. The line that specifically gives me an error is

    template <typename Item>
    ostream& operator<<(ostream& out, const Set<Item> &S)

    the error it gives me is ::
    bash-2.05b$ g++ setwithtemplates.cpp
    setwithtemplates.cpp:25: warning: friend declaration `std: stream&
    operator<<(std: stream&, const set<Item>&)' declares a non-template
    setwithtemplates.cpp:25: 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 thi
    zK says:
    s warning
    /tmp/cc7w8oWB.o(.text+0x1d8): In function `main':
    : undefined reference to `operator<<(std::basic_ostream<char, std::char_traits<char> >&, set<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&)'
    collect2: ld returned 1 exit status

    I Speak in frequencies even dogs have trouble hearing

  2. #2
    Junior Member
    Join Date
    Oct 2003
    The code you posted is correct but reading your error shows that the problem does not lie within that line. "warning: friend decleration of operator << declares a non-template function" that gives me the idea that in your class implementation of Set your decleration of the friend function does not match up with its definition. So check out the decleration and if you can't figure it out please post the class definition here.

Posting Permissions

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