Thread View: gnu.g++.bug
1 messages
1 total messages
Started by Dave Newton
Mon, 27 Nov 1989 21:41
Overloaded const bug.
Author: Dave Newton
Date: Mon, 27 Nov 1989 21:41
Date: Mon, 27 Nov 1989 21:41
51 lines
2091 bytes
2091 bytes
/*
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads