在C++中通常用某种前缀命名成员变量来表示它们是成员变量而不是局部变量或参数.如果你来自MFC背景,你可能会使用m_foo.我myFoo偶尔也见过.
C#(或者可能只是.NET)似乎建议只使用下划线,如_foo.这是否允许C++标准?
template<unsigned int n>
struct Factorial {
enum { value = n * Factorial<n-1>::value};
};
template<>
struct Factorial<0> {
enum {value = 1};
};
int main() {
std::cout << Factorial<5>::value;
std::cout << Factorial<10>::value;
}
Run Code Online (Sandbox Code Playgroud)
上面的程序在编译期间计算阶乘值.我想在编译时打印阶乘值,而不是在运行时使用cout打印.我们怎样才能在编译时打印阶乘值?
我正在使用VS2009.
谢谢!