| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"ciccio" |
| Date: |
11 Jan 2008 05:48:43 AM |
| Object: |
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)
.
|
|
| User: "Ondra Holub" |
|
| Title: Re: identical function names in and out a class can't compile |
11 Jan 2008 05:53:06 AM |
|
|
On 11 Led, 12:48, ciccio <no_valid_em...@spam.com> 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)
class bar {
void foo(int a) { ::foo(a,a); }
};
.
|
|
|
| User: "ciccio" |
|
| Title: Re: identical function names in and out a class can't compile |
11 Jan 2008 06:05:35 AM |
|
|
Ondra Holub wrote:
On 11 Led, 12:48, ciccio <no_valid_em...@spam.com> wrote:
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
.
|
|
|
|
|
| User: "Ron Natalie" |
|
| Title: Re: identical function names in and out a class can't compile |
11 Jan 2008 07:00:42 AM |
|
|
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.
.
|
|
|
|

|
Related Articles |
|
|