473,396 Members | 1,799 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,396 software developers and data experts.

identical function names in and out a class can't compile

Hi,

I don't know, but why is this not compiling? As far as I see there is
no ambiguity

regards

[]$ cat samename.cpp
#include <iostream>
void foo(int a, int b) {
std::cout << a+b << std::endl;
}
class bar {
void foo(int a) { foo(a,a); }
};

[]$ g++ -c samename.cpp
samename.cpp: In member function ‘void bar::foo(int)’:
samename.cpp:8: error: no matching function for call to ‘bar::foo(int&,
int&)’
samename.cpp:8: note: candidates are: void bar::foo(int)
Jan 11 '08 #1
3 1123
On 11 Led, 12:48, ciccio <no_valid_em...@spam.comwrote:
Hi,

I don't know, but why is this not compiling? As far as I see there is
no ambiguity

regards

[]$ cat samename.cpp
#include <iostream>
void foo(int a, int b) {
std::cout << a+b << std::endl;}

class bar {
void foo(int a) { foo(a,a); }

};

[]$ g++ -c samename.cpp
samename.cpp: In member function 'void bar::foo(int)':
samename.cpp:8: error: no matching function for call to 'bar::foo(int&,
int&)'
samename.cpp:8: note: candidates are: void bar::foo(int)
class bar {
void foo(int a) { ::foo(a,a); }

};
Jan 11 '08 #2
Ondra Holub wrote:
On 11 Led, 12:48, ciccio <no_valid_em...@spam.comwrote:
>Hi,

I don't know, but why is this not compiling? As far as I see there is
no ambiguity
<snip>
class bar {
void foo(int a) { ::foo(a,a); }

};
WOOOOW ... respect!!! Thanks a lot
Jan 11 '08 #3
ciccio wrote:
Hi,

I don't know, but why is this not compiling? As far as I see there is
no ambiguity

regards

[]$ cat samename.cpp
#include <iostream>
void foo(int a, int b) {
std::cout << a+b << std::endl;
}
class bar {
void foo(int a) { foo(a,a); }
};

[]$ g++ -c samename.cpp
samename.cpp: In member function ‘void bar::foo(int)’:
samename.cpp:8: error: no matching function for call to ‘bar::foo(int&,
int&)’
samename.cpp:8: note: candidates are: void bar::foo(int)
First the NAME is looked up. This yields bar::foo
Then overloads for THAT name are considered. THere
is only one overload for bar::foo and that is the one taking a single int.
Jan 11 '08 #4

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

Similar topics

1
by: Phil Powell | last post by:
Consider these two classes. Class Accepter in placement_classes.inc.php works as a form validation object, and it works like a charm: PHP: // placement_classes.inc.php - THIS ONE WORKS! ...
8
by: Nick Coghlan | last post by:
Time for another random syntax idea. . . So, I was tinkering in the interactive interpreter, and came up with the following one-size-fits-most default argument hack: Py> x = 1 Py> def...
2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
8
by: Ares Lagae | last post by:
When adopting the coding style of the standard C++ library, you often run into naming problems because class names are lower case, and member functions do not have get/set prefixes. For example:...
1
by: A. Saksena | last post by:
Hi all, I am trying to compile following code :- ======================================= #include <iostream.h> #include <string> namespace tlm { template <typename REQUEST, typename RESPONSE >...
6
by: Andre Eisenbach | last post by:
Should this code compile or not? class A { void f(); }; class B { friend void A::f();
2
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
4
by: Dan Krantz | last post by:
I have the following template to ensure that a given number (val) falls into a range (between vmin & vmax): template<typename T> T ForceNumericRange( const T& val, const T& vmin, const T& vmax)...
7
by: Icario | last post by:
I have an error when i compile this: class A { public: void f(A&) {} }; class B: public A { public: void f(B&) {}
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.