new
operator and do other horrible hacks like that, there's still plenty of times you end up bumping into the edges of the standard.
One great feature is method overloading: having the same method name with different argument types.
class my_holder { void add(int) ; void add(const char *) ; } ;So I was expecting everything to work fine when I used multiple inheritance, where each class had the same method name, but with different arguments:
class a { void add(int) ; } ; class b { void add(const char *) ; } ; class combine: public a, public b { } ; { combine test ; test.add(1) ; }But it didn't work. Instead I got:
testopero.cpp: In function `int main (int, char **)': testopero.cpp:22: request for member `add' is ambiguous testopero.cpp:7: candidates are: void a::add (int) testopero.cpp:10: void b::add (const char *)Hmmm. Can't decide between
add(int)
and add(const char *)
. Gee, I can. Can you? Check the reference guides just to see if there's some other magic code I need,
Nope, they say, "Don't do it." Thanks a lot.
I know those C++ compilers are already pretty messy (mostly thanks to the ability to compute square-roots at compile time with templates), but could we at least make them figure out which method to call when using multiple inheritance? I would really appreciate it.
[files]
The complete 20 line test program if you want to stretch your compiler:
#includeclass a { public: void add(int) ; } ; class b { public: void add(const char *) ; } ; void a::add(int aint) { printf("+ %d\n", aint) ; } void b::add(const char * astr) { printf("+ %s\n", astr) ; } class combine : public a, public b { } ; //// int main(int, char **) { int ival= 1 ; char s[10]= "hello" ; combine test ; test.add(ival) ; test.add(s) ; }
Feb '04
Oops I dropped by satellite.
New Jets create excitement in the air.
The audience is not listening.
Mar '04
Neat chemicals you don't want to mess with.
The Lack of Practise Effect
Apr '04
Scramjets take to the air
Doing dangerous things in the fire.
The Real Way to get a job
May '04
Checking out cool tools (with the kids)
A master geek (Ink Tank flashback)
How to play with your kids