fork(4) download
  1. #include <memory>
  2.  
  3.  
  4. using namespace std;
  5.  
  6.  
  7. class derived_op;
  8.  
  9.  
  10. template<class Op>
  11. class base_info :
  12. enable_shared_from_this<base_info<Op>>
  13. {
  14. public:
  15. void do_something_spawning_new_ops()
  16. {
  17. auto info =
  18. enable_shared_from_this<base_info<Op>>::shared_from_this();
  19. }
  20. };
  21.  
  22.  
  23. class derived_info :
  24. public base_info<derived_op>
  25. {
  26.  
  27. };
  28.  
  29.  
  30. template<class Info>
  31. class base_op
  32. {
  33. public:
  34. base_op(){}
  35. base_op(shared_ptr<base_op>){}
  36.  
  37. shared_ptr<Info> m_info;
  38. };
  39.  
  40.  
  41. class derived_op :
  42. public base_op<derived_info>
  43. {
  44. public:
  45. derived_op(){}
  46. derived_op(shared_ptr<base_op>){}
  47. };
  48.  
  49.  
  50. int main()
  51. {
  52. derived_op d;
  53. // Next line fails to compile.
  54. base_op<base_info> b;
  55.  
  56. return 0;
  57. }
  58.  
  59.  
Compilation error #stdin compilation error #stdout 0s 3136KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:54:22: error: type/value mismatch at argument 1 in template parameter list for 'template<class Info> class base_op'
     base_op<base_info> b;
                      ^
prog.cpp:54:22: error:   expected a type, got 'base_info'
prog.cpp:54:25: error: invalid type in declaration before ';' token
     base_op<base_info> b;
                         ^
stdout
Standard output is empty