fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<const char* s = "hello">
  5. class A {
  6. public:
  7. void foo();
  8. };
  9.  
  10. template<const char* s>
  11. void A<s>::foo() {
  12. cout << s;
  13. }
  14.  
  15. typedef A<" world"> B;
  16.  
  17. class C : public A<"!\n"> {};
  18.  
  19. int main() {
  20. A<"hello"> a;
  21. B b;
  22. C c;
  23. a.foo();
  24. b.foo();
  25. c.foo();
  26. return 0;
  27. }
Compilation error #stdin compilation error #stdout 0s 15240KB
stdin
Standard input is empty
compilation info
prog.cpp:15:19: error: ‘" world"’ is not a valid template argument for type ‘const char*’ because string literals can never be used in this context
 typedef A<" world"> B;
                   ^
prog.cpp:17:25: error: ‘"!\012"’ is not a valid template argument for type ‘const char*’ because string literals can never be used in this context
 class C : public A<"!\n"> {};
                         ^
prog.cpp: In function ‘int main()’:
prog.cpp:20:11: error: ‘"hello"’ is not a valid template argument for type ‘const char*’ because string literals can never be used in this context
  A<"hello"> a;
           ^
prog.cpp:23:4: error: request for member ‘foo’ in ‘a’, which is of non-class type ‘int’
  a.foo();
    ^~~
prog.cpp:24:4: error: request for member ‘foo’ in ‘b’, which is of non-class type ‘B {aka int}’
  b.foo();
    ^~~
prog.cpp:25:4: error: ‘class C’ has no member named ‘foo’
  c.foo();
    ^~~
stdout
Standard output is empty