fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template
  5. <int a>struct p:p
  6. <a+1>,p<a+2>{
  7. static int value=p
  8. <a+1>::val+p<a+2>::val;};
  9. template<>struct p<10>{static const int val=10;};
  10. template<> struct p<11>{static const int val=11;};
  11. int main() {
  12. p<1> pp;
  13. cout<< pp.val<<endl;
  14. // your code goes here
  15. return 0;
  16. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:8:20: error: ISO C++ forbids in-class initialization of non-const static member ‘p<a>::value’
 <a+1>::val+p<a+2>::val;};
                    ^~~
prog.cpp: In instantiation of ‘struct p<9>’:
prog.cpp:5:15:   recursively required from ‘struct p<2>’
prog.cpp:5:15:   required from ‘struct p<1>’
prog.cpp:12:9:   required from here
prog.cpp:7:12: error: ISO C++ forbids in-class initialization of non-const static member ‘p<9>::value’
 static int value=p
            ^~~~~
prog.cpp: In instantiation of ‘struct p<8>’:
prog.cpp:5:15:   recursively required from ‘struct p<2>’
prog.cpp:5:15:   required from ‘struct p<1>’
prog.cpp:12:9:   required from here
prog.cpp:7:12: error: ISO C++ forbids in-class initialization of non-const static member ‘p<8>::value’
prog.cpp:5:15: warning: direct base ‘p<10>’ inaccessible in ‘p<8>’ due to ambiguity
 <int a>struct p:p
               ^
prog.cpp: In instantiation of ‘struct p<7>’:
prog.cpp:5:15:   recursively required from ‘struct p<2>’
prog.cpp:5:15:   required from ‘struct p<1>’
prog.cpp:12:9:   required from here
prog.cpp:7:12: error: ISO C++ forbids in-class initialization of non-const static member ‘p<7>::value’
 static int value=p
            ^~~~~
prog.cpp:5:15: warning: direct base ‘p<9>’ inaccessible in ‘p<7>’ due to ambiguity
 <int a>struct p:p
               ^
prog.cpp: In instantiation of ‘struct p<6>’:
prog.cpp:5:15:   recursively required from ‘struct p<2>’
prog.cpp:5:15:   required from ‘struct p<1>’
prog.cpp:12:9:   required from here
prog.cpp:7:12: error: ISO C++ forbids in-class initialization of non-const static member ‘p<6>::value’
 static int value=p
            ^~~~~
prog.cpp:5:15: warning: direct base ‘p<8>’ inaccessible in ‘p<6>’ due to ambiguity
 <int a>struct p:p
               ^
prog.cpp: In instantiation of ‘struct p<5>’:
prog.cpp:5:15:   recursively required from ‘struct p<2>’
prog.cpp:5:15:   required from ‘struct p<1>’
prog.cpp:12:9:   required from here
prog.cpp:7:12: error: ISO C++ forbids in-class initialization of non-const static member ‘p<5>::value’
 static int value=p
            ^~~~~
prog.cpp:5:15: warning: direct base ‘p<7>’ inaccessible in ‘p<5>’ due to ambiguity
 <int a>struct p:p
               ^
prog.cpp: In instantiation of ‘struct p<4>’:
prog.cpp:5:15:   recursively required from ‘struct p<2>’
prog.cpp:5:15:   required from ‘struct p<1>’
prog.cpp:12:9:   required from here
prog.cpp:7:12: error: ISO C++ forbids in-class initialization of non-const static member ‘p<4>::value’
 static int value=p
            ^~~~~
prog.cpp:5:15: warning: direct base ‘p<6>’ inaccessible in ‘p<4>’ due to ambiguity
 <int a>struct p:p
               ^
prog.cpp: In instantiation of ‘struct p<3>’:
prog.cpp:5:15:   recursively required from ‘struct p<2>’
prog.cpp:5:15:   required from ‘struct p<1>’
prog.cpp:12:9:   required from here
prog.cpp:7:12: error: ISO C++ forbids in-class initialization of non-const static member ‘p<3>::value’
 static int value=p
            ^~~~~
prog.cpp:5:15: warning: direct base ‘p<5>’ inaccessible in ‘p<3>’ due to ambiguity
 <int a>struct p:p
               ^
prog.cpp: In instantiation of ‘struct p<2>’:
prog.cpp:5:15:   required from ‘struct p<1>’
prog.cpp:12:9:   required from here
prog.cpp:7:12: error: ISO C++ forbids in-class initialization of non-const static member ‘p<2>::value’
 static int value=p
            ^~~~~
prog.cpp:5:15: warning: direct base ‘p<4>’ inaccessible in ‘p<2>’ due to ambiguity
 <int a>struct p:p
               ^
prog.cpp: In instantiation of ‘struct p<1>’:
prog.cpp:12:9:   required from here
prog.cpp:7:12: error: ISO C++ forbids in-class initialization of non-const static member ‘p<1>::value’
 static int value=p
            ^~~~~
prog.cpp:5:15: warning: direct base ‘p<3>’ inaccessible in ‘p<1>’ due to ambiguity
 <int a>struct p:p
               ^
prog.cpp: In function ‘int main()’:
prog.cpp:13:14: error: request for member ‘val’ is ambiguous
    cout<< pp.val<<endl;
              ^~~
prog.cpp:10:42: note: candidates are: const int p<11>::val
 template<> struct p<11>{static const int val=11;};
                                          ^~~
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:10:42: note:                 const int p<11>::val
prog.cpp:9:41: note:                 const int p<10>::val
 template<>struct p<10>{static const int val=10;};
                                         ^~~
stdout
Standard output is empty