Skip to content

Instantly share code, notes, and snippets.

@Botffy
Created November 16, 2012 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Botffy/4085575 to your computer and use it in GitHub Desktop.
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.
#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