Skip to content

Instantly share code, notes, and snippets.

@onqtam
Last active August 29, 2015 14:21
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 onqtam/0f20ea4038f0f61adc63 to your computer and use it in GitHub Desktop.
Save onqtam/0f20ea4038f0f61adc63 to your computer and use it in GitHub Desktop.
#include <iostream>
struct A {
virtual void foo() = 0;
};
struct B {
virtual void foo() = 0;
};
struct CA : A {
void foo() override { std::cout << "A" << std::endl; }
};
struct CB : B {
void foo() override { std::cout << "B" << std::endl; }
};
struct C : CA, CB {
//void foo() override { std::cout << "C" << std::endl; } // if this is provided the ones from CA and CB will be overridden
};
int main() {
C c;
//c.foo(); // ambiguous
A& a = c;
a.foo();
B& b = c;
b.foo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment