thats called polymophism i believe. im not too advanced in oop, but i think thats it. its why the virtual keyword exists. wait no im wrong. i dont really know, but a google search unearthed this
http://stackoverflow.com/questions/2004820/inherit-interfaces-which-share-a-method-name
Actually, the compiler complains that the function is ambiguous.
(so you need to qualify with the class name to access the method.)
Also, note that this
class class1: public class2, class3
is using private inheritence for class3. As none of public, protected, or private is given, the default is used, which is private for classes (and public for structs.)
class class2
{
public:
void blah_blah() {
cout << "class2::blah_blah()" << endl;
}
};
class class3
{
public:
void blah_blah() {
cout << "class3::blah_blah()" << endl;
}
};
class class1: public class2, public class3
{
public:
void test() {
blah_blah();
}
};
MSVC
1>c:\cplusplus\test\main.cpp(25) : error C2385: ambiguous access of 'blah_blah'
1> could be the 'blah_blah' in base 'class2'
1> or could be the 'blah_blah' in base 'class3'
1>c:\cplusplus_vc9\temp_test\main.cpp(25) : error C3861: 'blah_blah': identifier not found
GCC
main.cpp: In member function 'void class1::test()':
main.cpp:25:9: error: reference to 'blah_blah' is ambiguous
main.cpp:16:10: error: candidates are: void class3::blah_blah()
main.cpp:8:10: error: void class2::blah_blah()