friend function template class declaration error

This is a discussion on friend function template class declaration error within the C++ Programming forums, part of the General Programming Boards category; this: Code: friend vector<type, n> (::operator/<>)(const type div, const vector<type, n>& v); generates this error: vector.h:45: error: expected `)' before ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    friend function template class declaration error

    this:

    Code:
    friend vector<type, n> (::operator/<>)(const type div, const vector<type, n>& v);
    generates this error:

    vector.h:45: error: expected `)' before < token

    why is that?

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    Probably because it's converting some of those characters into a different character. There are things like trigraphs that when put into code are converted to different characters. I don't know if that's what is happening here, but it's possible. That /<>) code looks suspicious.

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You haven't probably forward declared the function.

    Code:
    //uncomment to fix
    /*
    template <class T>
    class X;
    
    template <class T>
    X<T> operator/(const T div, const X<T>& v);
    */
    template <class T>
    class X
    {
        friend X<T> operator/<>(const T div, const X<T>& v);
    };
    
    int main()
    {
        X<int> x;
        10 / x;
    }
    
    //implementation
    template <class T>
    X<T> operator/(const T , const X<T>& ) { return X<T>(); }
    I don't entirely understand your use of extra brackets and the scope operator (they just change the wording of the error message).

    Read more in C++ FAQ.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21