fork download
  1. #include <map>
  2. #include <iostream>
  3. #include <utility>
  4. #include <typeinfo>
  5. #include <string>
  6. class A {};
  7. class B {};
  8. struct type_forward
  9. {
  10. /// NOTE: Add more type-forwarding here
  11. struct type_impl
  12. {
  13. typedef int key_type;
  14. };
  15. struct A_forward: public type_impl
  16. {
  17. typedef A type;
  18. };
  19. struct B_forward: public type_impl
  20. {
  21. typedef B type;
  22. };
  23. struct string_forward: public type_impl
  24. {
  25. typedef std::string type;
  26. };
  27. static std::map<type_impl::key_type, type_impl> type_forwardings;
  28. };
  29. std::map<type_forward::type_impl::key_type, type_forward::type_impl> type_forward::type_forwardings =
  30. std::map<type_forward::type_impl::key_type, type_forward::type_impl>();
  31. int main()
  32. {
  33. type_forward::type_forwardings.insert({1, type_forward::A_forward()});
  34. type_forward::type_forwardings.insert({2, type_forward::B_forward()});
  35. type_forward::type_forwardings.insert({3, type_forward::string_forward()});
  36. auto X(type_forward::type_forwardings.at(1));
  37. auto XX(type_forward::type_forwardings.at(2));
  38. auto XXX(type_forward::type_forwardings.at(3));
  39.  
  40. decltype(X)::type Z; /// Z doit être de type A !
  41. decltype(XX)::type ZZ; /// ZZ doit être de type B !
  42. decltype(XXX)::type ZZZ; /// ZZZ doit être de type std::string !
  43. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:40:5: error: ‘type’ is not a member of ‘type_forward::type_impl’
prog.cpp:40:23: error: expected ‘;’ before ‘Z’
prog.cpp:41:5: error: ‘type’ is not a member of ‘type_forward::type_impl’
prog.cpp:41:24: error: expected ‘;’ before ‘ZZ’
prog.cpp:42:5: error: ‘type’ is not a member of ‘type_forward::type_impl’
prog.cpp:42:25: error: expected ‘;’ before ‘ZZZ’
stdout
Standard output is empty