Afficher un message
Vieux 06/12/2007, 16h52   #1
Darko
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Am I the only one mad here?

The following code doesn't work:

01: class A {
02: public:
03: bool f( int x )
04: {
05: return x>1;
06: }
07: };
08:
09: class B: public A {
10: public:
11: bool f()
12: {
13: return f(3) ;
14: }
15: };
16:
17: int main()
18: {}

Compiler reports the following error:
g++ proba.cpp -o proba
proba.cpp: In member function `bool B::f()':
proba.cpp:13: error: no matching function for call to `B::f(int)'
proba.cpp:12: note: candidates are: bool B::f()
make: *** [proba] Error 1

Since I suppose you are going to propose putting A::f(3), I can tell
you I've already tried to do that and it works. But:
* Why would I have to do that!? The methods are perfectly distinct
having different arguments.
* If I do that, then the following code still doesnt work:

01: class A {
02: public:
03: bool f( int x )
04: {
05: return x>1;
06: }
07: };
08:
09: class B: public A {
10: public:
11: bool f()
12: {
13: return A::f(3) ;
14: }
15: };
16:
17: int main()
18: {
19: B b;
20: b.f( 4 );
21: }
giving the following error:

proba.cpp: In function `int main()':
proba.cpp:20: error: no matching function for call to `B::f(int)'
proba.cpp:12: note: candidates are: bool B::f()
make: *** [proba] Error 1

Now what do you think about that? Personally, it broke my C++
confidence.

Regards,

Darko
  Réponse avec citation
 
Page generated in 0,05813 seconds with 9 queries