bug report

Michael Orlov orlovm@CS.BGU.AC.IL
Sun May 14 10:26:00 GMT 2000


Version:
--------

orlovm-silver:~/progs/c> g++ -v
Reading specs from /usr/local/gcc-2.95.2/lib/gcc-lib/sparc-sun-solaris2.6/2.95.2/specs
gcc version 2.95.2 19991024 (release)

System Type (also checked on linux)
-----------------------------------

orlovm-silver:~/progs/c> uname -a
SunOS silver 5.6 Generic_105181-19 sun4u sparc SUNW,Ultra-4

Command line
------------

orlovm-silver:~/progs/c> g++ -o a a.cc
a.cc: In function `int main()':
a.cc:17: no matching function for call to `B::boo ()'
a.cc:10: candidates are: int B::boo(int)
a.cc:18: no matching function for call to `B::boo ()'
a.cc:10: candidates are: int B::boo(int)

Source
------

#include <iostream.h>

class A {
public:
  int boo() { return 1; }
};

class B : public A {
public:
  int boo(int a) { return a; }
};


int main() {
  B *b = new B();
  B bb;
  cout << "Blah: " << b->boo() << endl;
  cout << "Blah: " << bb.boo() << endl;
  delete b;
  return 0;
}

Problem
-------

The compiler reports an error probably because it doesn't
recognize that the reference b->boo() is to a function from the
superclass A, and not an erroneous attempt to use a function from
B.

Were the function int B::boo(int) not defined, the code would compile.


More information about the Gcc-bugs mailing list