template<int n>
struct Numberim{
enum{ value = Numberim<n-1>::value + n };
};
template<>
struct Numberim<0>{
enum{ value = 0 };
};
this is a simple tmp example,and it’s ok;
template<int n>
class Numberim{
enum{ value = Numberim<n-1>::value + n };
};
template<>
class Numberim<0>{
enum{ value = 0 };
};
I use g++ to compile,and it complains…however, as far as I know, struct and class is treated nearly in the same way.just like this”In C++, the only difference between a struct and a class is that struct members are public by default, and class members are private by default.”
So, what’s the difference between them here in earth?
The difference will be same as it would be for typically class vs struct. Your “value” will be public for your first example (using struct) and private for your second example (using class).
For a reference on the difference between a class and a struct, please see What are the differences between struct and class in C++.