friend operator>> function declaration for a template class

Discussion in 'C++' started by Yu Lianqing, Apr 4, 2004.

  1. Yu Lianqing

    Yu Lianqing Guest

    Hi, all

    I am writing an overloading operator >> function for a template class
    and can't make it right. G++ 3.2 (Redhat8.0) gives the following
    errors:

    g++ -c list.cxx
    In file included from SLinkList.cxx:3,
    from list.cxx:1:
    SLinkList.h:20: ISO C++ forbids declaration of `type name' with no
    type
    SLinkList.h:20: friend declaration requires class-key, i.e. `friend
    int'
    SLinkList.h:20: parse error before `template'
    make: *** [list.o] Error 1

    Here is the relevant code segments:

    // declaration in SLinkList.h
    template <class Type>
    class SLinkList {
    friend template <class Type>
    istream& operator>>( istream&, SLinkList<Type>& );
    ...
    };

    // definition in SLinkList.cxx
    template <class ElemType>
    istream& operator>>( istream &is, SLinkList<ElemType> &slist )
    {
    ...
    }

    Any help appreciated!

    Leonard
    3/4/2004
    Yu Lianqing, Apr 4, 2004
    #1
    1. Advertising

  2. Yu Lianqing

    Leor Zolman Guest

    On 3 Apr 2004 17:17:07 -0800, (Yu Lianqing)
    wrote:

    >Hi, all
    >
    >I am writing an overloading operator >> function for a template class
    >and can't make it right. G++ 3.2 (Redhat8.0) gives the following
    >errors:
    >
    >g++ -c list.cxx
    >In file included from SLinkList.cxx:3,
    > from list.cxx:1:
    >SLinkList.h:20: ISO C++ forbids declaration of `type name' with no
    >type
    >SLinkList.h:20: friend declaration requires class-key, i.e. `friend
    >int'
    >SLinkList.h:20: parse error before `template'
    >make: *** [list.o] Error 1
    >
    >Here is the relevant code segments:
    >
    >// declaration in SLinkList.h
    >template <class Type>
    >class SLinkList {
    > friend template <class Type>
    > istream& operator>>( istream&, SLinkList<Type>& );


    Take that word "friend" and move it from before "template" to before
    "istream &". You may also want to choose a different name for one of those
    template type parameters (don't use "Type" in both places).
    -leor


    --
    Leor Zolman --- BD Software --- www.bdsoft.com
    On-Site Training in C/C++, Java, Perl and Unix
    C++ users: Download BD Software's free STL Error Message Decryptor at:
    www.bdsoft.com/tools/stlfilt.html
    Leor Zolman, Apr 4, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. john smith
    Replies:
    1
    Views:
    1,909
    Victor Bazarov
    Aug 10, 2003
  2. Layton
    Replies:
    2
    Views:
    455
    Layton
    Sep 27, 2006
  3. Replies:
    4
    Views:
    6,928
    Ian Collins
    Jan 26, 2007
  4. Replies:
    2
    Views:
    510
    Rolf Magnus
    Jan 26, 2007
  5. A L
    Replies:
    1
    Views:
    510
    Alf P. Steinbach /Usenet
    Aug 25, 2010
Loading...

Share This Page