fork(2) download
  1. struct B_crtp;
  2. template<class Derived> struct B_crtp_base;
  3.  
  4. template<class Derived>
  5. struct A_crtp_base {
  6.  
  7. operator B_crtp_base<B_crtp>();
  8. };
  9.  
  10. struct A_crtp : A_crtp_base<A_crtp> {
  11. };
  12.  
  13. template<class Derived> struct B_crtp_base : A_crtp_base<B_crtp_base<Derived>> {};
  14.  
  15. struct B_crtp : B_crtp_base<B_crtp> {};
  16.  
  17. template<class Derived>
  18. A_crtp_base<Derived>::operator B_crtp_base<B_crtp>()
  19. {
  20. return B_crtp_base<B_crtp>(); // Whatever, make sure this is set with common A_crtp_base stuff
  21. }
  22.  
  23. int main()
  24. {
  25. A_crtp a;
  26. B_crtp b;
  27.  
  28. static_cast< B_crtp_base<B_crtp>& >(b) = a;
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 3292KB
stdin
Standard input is empty
stdout
Standard output is empty