fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. // Class definition
  5. template <typename T> class foo
  6. {
  7. public:
  8. // Constructor
  9. foo(T value) { this->value = value; }
  10. // Public function
  11. T twice() { return this->value + this->value; }
  12.  
  13. private:
  14. // Private function
  15. void bar() { }
  16. // Private member
  17. T value;
  18. };
  19.  
  20. int main()
  21. {
  22. foo f1(1);
  23. foo f2(std::string("1"));
  24.  
  25. std::cout << f1.twice() << '\n';
  26. std::cout << f2.twice() << '\n';
  27. std::cout << foo<float>(3.14).twice() << '\n';
  28.  
  29. return 0;
  30. }
Compilation error #stdin compilation error #stdout 0s 3472KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:22:6: error: missing template arguments before ‘f1’
  foo f1(1);
      ^
prog.cpp:22:6: error: expected ‘;’ before ‘f1’
prog.cpp:23:6: error: missing template arguments before ‘f2’
  foo f2(std::string("1"));
      ^
prog.cpp:23:6: error: expected ‘;’ before ‘f2’
prog.cpp:25:15: error: ‘f1’ was not declared in this scope
  std::cout << f1.twice() << '\n';
               ^
prog.cpp:26:15: error: ‘f2’ was not declared in this scope
  std::cout << f2.twice() << '\n';
               ^
stdout
Standard output is empty