473,699 Members | 2,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6988

"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==(cons t 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
5008
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, std::char_traits<char> >& << Thing&' operator friendop.cpp:27: candidates are: std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>&, const Thing&) friendop.cpp:14: std::basic_ostream<_CharT, _Traits>&...
3
1587
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; // here x contains "004400C8pluto"
1
2130
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 the same error. Here is the code of the class template< class T > class Matrix { friend ostream &operator << <>( ostream &, const Matrix< T > & ); friend istream &operator >> <>( istream &, Matrix< T > & ); public: ...
0
1673
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 errors..Not able to proceed further.(./configure went smooth). I request you to provide suggestions to solve this problem. -5.2.1/include -I/lamp/php-5.2.1/main -I/lamp/php-5.2.1 -I/usr/local/ include/libxml2 -I/lamp/php-5.2.1/ext/date/lib...
2
2080
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 // conditional compilation #define POLYNOMIAL_H # include <iostream> using namespace std;
2
2152
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 includes both the file listed below) The messages are: In file included from unit-dev.cpp:27: D:/Documents and Settings/Zachary/My Documents/School/G11/Computer Science/VirtOS/src/ipc/messagehandler.h:27: error: using-declaration for non-member at...
0
1145
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 <) friend ostream & operator << <(ostream & os, Vector <T& tab); for other declaration ( not friend), the + operator, it works !! here is a complete example with errors at the compilation step. If I omit the << operator, the program will run
3
1368
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 statement?
6
30697
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 names "Denom" I'm guessing it has something to do with the declaration of these private objects in the .h file, and it's use in the source code here's a snippet of one of the functions
20
3247
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 Copyright (C) Microsoft Corporation. All rights reserved.
0
8703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9185
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7773
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.