fork(4) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<int a> class T{
  5. namespace A{
  6. int f1();
  7. int f2();
  8. }
  9. namespace B{
  10. int f1();
  11. int f2();
  12. }
  13. public:
  14. void test();
  15. };
  16.  
  17. template<int a> void T<a>::test(){cout<<a<<A::f1()<<A::f2()<<B::f1()<<B::f2();}
  18. template<int a> int T<a>::A::f1(){return a+1;}
  19. template<int a> int T<a>::A::f2(){return a-1;}
  20. template<int a> int T<a>::B::f1(){return a*2;}
  21. template<int a> int T<a>::B::f2(){return a*3;}
  22.  
  23. int main() {
  24. T<2> t;
  25. t.test();
  26. return 0;
  27. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5:2: error: expected unqualified-id before 'namespace'
  namespace A{
  ^
prog.cpp:9:2: error: expected unqualified-id before 'namespace'
  namespace B{
  ^
prog.cpp: In member function 'void T<a>::test()':
prog.cpp:17:44: error: 'A' has not been declared
 template<int a> void T<a>::test(){cout<<a<<A::f1()<<A::f2()<<B::f1()<<B::f2();}
                                            ^
prog.cpp:17:53: error: 'A' has not been declared
 template<int a> void T<a>::test(){cout<<a<<A::f1()<<A::f2()<<B::f1()<<B::f2();}
                                                     ^
prog.cpp:17:62: error: 'B' has not been declared
 template<int a> void T<a>::test(){cout<<a<<A::f1()<<A::f2()<<B::f1()<<B::f2();}
                                                              ^
prog.cpp:17:71: error: 'B' has not been declared
 template<int a> void T<a>::test(){cout<<a<<A::f1()<<A::f2()<<B::f1()<<B::f2();}
                                                                       ^
prog.cpp: At global scope:
prog.cpp:18:21: error: 'T<a>::A' is not a type
 template<int a> int T<a>::A::f1(){return a+1;}
                     ^
prog.cpp:18:33: error: invalid use of dependent type 'typename T<a>::A'
 template<int a> int T<a>::A::f1(){return a+1;}
                                 ^
prog.cpp:19:21: error: 'T<a>::A' is not a type
 template<int a> int T<a>::A::f2(){return a-1;}
                     ^
prog.cpp:19:33: error: invalid use of dependent type 'typename T<a>::A'
 template<int a> int T<a>::A::f2(){return a-1;}
                                 ^
prog.cpp:20:21: error: 'T<a>::B' is not a type
 template<int a> int T<a>::B::f1(){return a*2;}
                     ^
prog.cpp:20:33: error: invalid use of dependent type 'typename T<a>::B'
 template<int a> int T<a>::B::f1(){return a*2;}
                                 ^
prog.cpp:21:21: error: 'T<a>::B' is not a type
 template<int a> int T<a>::B::f2(){return a*3;}
                     ^
prog.cpp:21:33: error: invalid use of dependent type 'typename T<a>::B'
 template<int a> int T<a>::B::f2(){return a*3;}
                                 ^
stdout
Standard output is empty