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

C

ciccio

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)
 
O

Ondra Holub

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); }

};
 
R

Ron Natalie

ciccio said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top