#include <iostream> using namespace std; template <int a>struct p:p <a+1>,p<a+2>{ static int value=p <a+1>::val+p<a+2>::val;}; template<>struct p<10>{static const int val=10;}; template<> struct p<11>{static const int val=11;}; int main() { p<1> pp; cout<< pp.val<<endl; // your code goes here return 0; }
Standard input is empty
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;}; ^~~
Standard output is empty