fork(1) download
  1. template <typename derived>
  2. struct test_base {
  3. derived baz() { return *static_cast<derived *>(this); }
  4. };
  5.  
  6. template <int N>
  7. struct test : public test_base<test<N>> {
  8. };
  9.  
  10. template <>
  11. struct test<2> : public test_base<test<2>> {
  12. test bar() { return *this; }
  13. };
  14.  
  15. int main() {
  16. test<1> a = {};
  17. test<2> b = {};
  18.  
  19. auto c = a.baz();
  20. auto d = b.baz();
  21. auto e = b.bar();
  22.  
  23. if (&c && &d && &e)
  24. return 0;
  25. else
  26. return 1;
  27. }
Success #stdin #stdout 0s 3336KB
stdin
Standard input is empty
stdout
Standard output is empty