newton%cadillac.cad.mcc.com@MCC.COM (Dave Newton) (11/28/89)
/* Overloaded const Bug? The program below declares t1::fun() as a const member and t2::fun() as an overloaded nonconst member. In the main program when "fun()" is called directly everythings works as I expected. However when "fun()" is call via the member function "t1:dave()" "t1:fun()" get called instead of "t2:fun()". */ #include <stream.h> class t1 { public: virtual const char* fun() const; void dave(); }; const char* t1::fun() const {cout << "t1:fun()\n"; return NULL;} void t1::dave() {fun();} class t2: public t1 { public: const char* fun(); }; const char* t2::fun() {cout << "t2:fun()\n"; return NULL;} main() { t2 a; a.fun(); // prints t2:fun() a.dave(); // prints t1:fun(). I expected t2:fun() to be printed since // a is not a const object. } /* Machine: SUN3 Operating System V4.02 Compiler Information: g++ -v -o test test.cc gcc version 1.36.1 (based on GCC 1.36) /usr/local/gnu/1.36/lib/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 test.cc /usr/tmp/cca02573.cpp GNU CPP version 1.36 /usr/local/gnu/1.36/lib/gcc-cc1plus /usr/tmp/cca02573.cpp -quiet -dumpbase test.cc -version -o /usr/tmp/cca02573.s GNU C++ version 1.36.1 (based on GCC 1.36) (68k, MIT syntax) compiled by GNU C version 1.36. default target switches: -m68020 -mc68020 -m68881 -mbitfield test /usr/local/gnu/1.36/lib/gcc-as -mc68020 -o test.o /usr/tmp/cca02573.s /usr/local/gnu/1.36/lib/gcc-ld -o test -e start -dc -dp /lib/crt0.o /lib/Mcrt1.o test.o -lg++ /usr/local/gnu/1.36/lib/gcc-gnulib -lc