Created
November 16, 2012 08:48
-
-
Save Botffy/4085575 to your computer and use it in GitHub Desktop.
dreaded diamond with a twist: granddad has no members, but has a method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
struct granddad { | |
void helloes() { | |
std::cout << "helloes" << std::endl; | |
} | |
}; | |
struct dad : public granddad { | |
int a; | |
}; | |
struct mom : public granddad { | |
int b; | |
}; | |
struct freak: public mom, public dad {}; | |
int main() { | |
freak f; | |
//f.helloes(); | |
/* | |
produces error: | |
inheri.cpp: In function ‘int main()’: | |
inheri.cpp:83: error: request for member ‘helloes’ is ambiguous | |
inheri.cpp:54: error: candidates are: void granddad::helloes() | |
inheri.cpp:54: error: void granddad::helloes() | |
(heh) | |
*/ | |
f.mom::helloes(); // works! | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment