Overloaded functions in C++ (bug?)
miguel_l@airtel.net
miguel_l@airtel.net
Sat Mar 11 15:22:00 GMT 2000
I admit that I am not a C++ expert, so maybe this is not a bug. The
problem is that declaring a function within a class prevents the compiler
from seeing other functions with the same name but different parameters,
which would otherwise be visible.
For example, I get an error for this code:
-------------------------------------------------------------------------
class A {
public:
void f();
};
class B : public A {
public:
void f(int);
void g();
};
void B::g() {
f();
}
$ g++ -O2 -c p3.cpp -o p3.o
p3.cpp: In method `void B::g()':
p3.cpp:13: no matching function for call to `B::f ()'
p3.cpp:8: candidates are: void B::f(int)
-------------------------------------------------------------------------
And for this code:
-------------------------------------------------------------------------
void f();
class B {
public:
void f(int);
void g();
};
void B::g() {
f();
}
$ g++ -O2 -c p4.cpp -o p4.o
p4.cpp: In method `void B::g()':
p4.cpp:10: no matching function for call to `B::f ()'
p4.cpp:5: candidates are: void B::f(int)
-------------------------------------------------------------------------
I'm using gcc version 2.95.2:
-------------------------------------------------------------------------
$ g++ -v
Reading specs from /usr/local/lib/gcc-lib/i686-redhat-linux/2.95.2/specs
gcc version 2.95.2 19991024 (release)
-------------------------------------------------------------------------
Yes, I know that I could work around by using `A::f()' in the first
example and `::f()' in the second one. But I'd like to know whether
current gcc behaviour is according to the standard or this is a genuine
bug. I've read the FAQ, but I haven't found any reference to this kind
of problem.
I'm not subscribed to the gcc-bugs mailing list. I'll search the list
archive for replies, but I'd appreciate if you cc'd them to me. Thanks in
advance.
--
Miguel
More information about the Gcc-bugs
mailing list