fork(2) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. template <typename T>
  7. void foo(){
  8. T::value_type bar('a');
  9.  
  10. cout << bar << endl;
  11. }
  12.  
  13. int main() {
  14. foo<string>();
  15.  
  16. return 0;
  17. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void foo()':
prog.cpp:8:2: error: need 'typename' before 'T:: value_type' because 'T' is a dependent scope
  T::value_type bar('a');
  ^
prog.cpp:8:16: error: expected ';' before 'bar'
  T::value_type bar('a');
                ^
prog.cpp:10:10: error: 'bar' was not declared in this scope
  cout << bar << endl;
          ^
prog.cpp: In instantiation of 'void foo() [with T = std::basic_string<char>]':
prog.cpp:14:14:   required from here
prog.cpp:8:2: error: dependent-name 'T:: value_type' is parsed as a non-type, but instantiation yields a type
  T::value_type bar('a');
  ^
prog.cpp:8:2: note: say 'typename T:: value_type' if a type is meant
stdout
Standard output is empty