473,320 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

error: declaration of `operator==' as non-function

Hi,

GNU g++ 3.4 detects an error in code below.
What is wrong here?

--------- [C++] foo.cpp : BEGIN ---------

template <typename T>
struct Foo
{
friend bool operator== <T> (const Foo<T>&, const Foo<T>&); // Line#4
};

template <typename T>
bool operator== (const Foo<T>&, const Foo<T>&)
{
return false;
}

int main()
{
Foo<int> foo;
return 0;
}

--------- [C++] foo.cpp : END -----------

------ Compilation with GNU gcc 3.3 (Cygwin) : BEGIN ------

$ g++ --version
g++ (GCC) 3.3.3 (cygwin special)
[---omitted---]

$ g++ foo.cpp
// No errors/warnings

------ Compilation with GNU gcc 3.3 (Cygwin) : END --------

------ Compilation with GNU gcc 3.4 (DJGPP) : BEGIN ------

$ gpp --version
gpp.exe (GCC) 3.4.1
[---omitted---]
$ gpp foo.cpp

foo.cpp:4: error: declaration of `operator==' as non-function
foo.cpp:4: error: expected `;' before '<' token
------ Compilation with GNU gcc 3.4 (DJGPP) : END --------

--
Alex Vinokur
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn


Jul 22 '05 #1
2 6963

"Alex Vinokur" <al****@big-foot.com> wrote in message
Hi,

GNU g++ 3.4 detects an error in code below.
What is wrong here?

--------- [C++] foo.cpp : BEGIN ---------

template <typename T>
struct Foo
{
friend bool operator== <T> (const Foo<T>&, const Foo<T>&); // Line#4


Shouldn't it be just - friend bool operator== (const Foo<T>&, const
Foo<T>&); // Line#4

Sharad
Jul 22 '05 #2

"Sharad Kala" <no*****************@yahoo.com> wrote in message news:2s*************@uni-berlin.de...

"Alex Vinokur" <al****@big-foot.com> wrote in message
Hi,

GNU g++ 3.4 detects an error in code below.
What is wrong here?

--------- [C++] foo.cpp : BEGIN ---------

template <typename T>
struct Foo
{
friend bool operator== <T> (const Foo<T>&, const Foo<T>&); // Line#4


Shouldn't it be just - friend bool operator== (const Foo<T>&, const
Foo<T>&); // Line#4

Sharad


If I put line
friend bool operator== (const Foo<T>&, const Foo<T>&); // // Line#4
instead
friend bool operator== <T> (const Foo<T>&, const Foo<T>&); // Line#4
GNU gpp 3.4.1 produces the following warnings:

foo.cpp:4: warning: friend declaration `bool operator==(const Foo<T>&, const
oo<T>&)' declares a non-template function
foo.cpp:4: warning: (if this is not what you intended, make sure the function
template has already been declared and add <> after the function name here) -W
-non-template-friend disables this warning

Because I need template operator== the program should be rewritten as following:

--------- [C++] foo.cpp : BEGIN ---------
template <typename T>
struct Foo;

template <typename T>
bool operator== (const Foo<T>&, const Foo<T>&);

template <typename T>
struct Foo
{
friend bool operator== <> (const Foo<T>&, const Foo<T>&);
};

template <typename T>
bool operator== (const Foo<T>&, const Foo<T>&)
{
return false;
}

int main()
{
Foo<int> foo;
return 0;
}
--------- [C++] foo.cpp : END -----------

Now GNU gpp 3.4.1 accepts it.

Thanks.

--
Alex Vinokur
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn


Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Gianni Mariani | last post by:
Can anyone enligten me why I get the "ambiguous overload" error from the code below: friendop.cpp: In function `int main()': friendop.cpp:36: ambiguous overload for `std::basic_ostream<char,...
3
by: Carlo Capelli | last post by:
I found a change in the following code, that behaved correctly in VC++ 6. #include <strstream> using namespace std; void main() { char x; ostrstream(x, 100) << "pippo" << "pluto" << ends;...
1
by: atomik.fungus | last post by:
Hi, as many others im making my own matrix class, but the compiler is giving me a lot of errors related to the friend functions which overload >> and <<.I've looked around and no one seems to get...
0
by: tsivaraman | last post by:
I am trying to build php-5.2.1 in RedHat Linux 9. I have installed libxml2-2.6.11,mysql-5.0.33,httpd-2.2.4(apache) successfully.When i do 'make' from the php directory,i get the following...
2
by: KiranJyothi | last post by:
Can anyone please tell me how can I rectify my compile time error in this program. /********************************HEADER FILE***********************************/ #ifndef POLYNOMIAL_H //...
2
by: sydneytroz | last post by:
I'm getting a rather odd set of error messages when I try compiling the below code. I'm using the Dev-C++ IDE on WinXP, and am using a small driver program (unit-dev.cpp) to test the classes (it...
0
by: abelahcene | last post by:
Hi, Is it a bug ?? I tried to compile a cpp program which ran correctly on previous release (sarge debian, gcc compiler 3 ), it gave errors, for the declaration (even if I omit the symbols <) ...
3
by: TS | last post by:
short x = 1; //this has build error saying missing conversion x = x + 2; Why can't you just add this? I guess the 1 is a literal that translates to an int32? How would I accomplish this...
6
by: Myxamatosis | last post by:
Upon compiling my code for a fraction class, the error that i get is a good 50 or so repetitions of error: Class "Fraction" has no member named "Numer" and error: Class "Fraction" has no member...
20
by: jacob navia | last post by:
Consider this code static typedef struct { int boo; } FOO; This provokes with MSVC: ------------------------------ Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.