C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-19-2009, 08:37 PM   #1
Registered User
 
Join Date: Jan 2008
Posts: 562
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?
-EquinoX- is offline   Reply With Quote
Old 11-20-2009, 12:22 PM   #2
Registered User
 
Join Date: Jan 2005
Posts: 7,252
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.
Daved is offline   Reply With Quote
Old 11-20-2009, 01:00 PM   #3
The larch
 
Join Date: May 2006
Posts: 3,222
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.

Quote:
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).
anon is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Another syntax error caldeira C Programming 31 09-05-2008 01:01 AM
Quantum Random Bit Generator shawnt C++ Programming 62 06-18-2008 10:17 AM
Dikumud maxorator C++ Programming 1 10-01-2005 06:39 AM
C++ compilation issues Rupan C++ Programming 1 08-22-2005 05:45 AM
Interface Question smog890 C Programming 11 06-03-2002 05:06 PM


All times are GMT -6. The time now is 10:48 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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