Skip to content

Instantly share code, notes, and snippets.

@emlun
Last active August 29, 2015 14:07
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 emlun/6df03ac4e3819603f189 to your computer and use it in GitHub Desktop.
Save emlun/6df03ac4e3819603f189 to your computer and use it in GitHub Desktop.
C++ classes have themselves as implicit inner class
struct Foo {
int x;
Foo() : x(0) {};
explicit Foo(int x) : x(x) {};
bool operator>(const Foo& other) const {
return x > other.x;
}
};
int main() {
const Foo a;
const typename Foo::Foo b(1);
const typename Foo::Foo::Foo c(2);
const bool a_gt_b = a > b;
const bool a_gt_c = a > c;
const bool b_gt_a = b > a;
const bool b_gt_c = b > c;
const bool c_gt_a = c > a;
const bool c_gt_b = c > b;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment