473,748 Members | 2,540 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 6993

"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
5012
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
1591
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
2134
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
1675
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
2083
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
2155
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
1147
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
1373
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
30728
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
3260
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
8995
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
8832
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,...
1
9332
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8252
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
6799
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
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
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

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.