Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- struct A {
- A();
- virtual bool operator==(const A&) const { printf("A==A\n"); return false; }
- };
- struct B : public A {
- bool operator==(const A&) const override { printf("B==A\n"); return false; }
- virtual bool operator==(const B&) const { printf("B==B\n"); return false; }
- };
- struct C final : public B {
- bool operator==(const B&) const override { printf("C==B\n"); return false; }
- bool operator==(const C&) const { printf("C==C\n"); return false; }
- };
- A::A() {
- static bool comparing = false;
- if(!comparing) {
- comparing = true;
- *this == B();
- comparing = false;
- }
- }
- int main() {
- // const A &a = B();
- // a == B(); printf("\n");
- // B() == a; printf("\n");
- B() == B(); printf("\n");
- // B() == C(); printf("\n");
- // C() == B(); printf("\n");
- C() == C(); printf("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement