首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自wiki的pow (Pow)模板实现

来自wiki的pow (Pow)模板实现
EN

Stack Overflow用户
提问于 2012-07-14 12:01:37
回答 1查看 867关注 0票数 5

可能重复: Template Metaprogramming - Difference Between Using Enum Hack and Static Const

请解释在下面的power模板实现中使用了什么for is enum

代码语言:javascript
复制
template<int B, int N>
struct Pow {
    // recursive call and recombination.
    enum{ value = B*Pow<B, N-1>::value };
};

template< int B >
struct Pow<B, 0> {
    // ''N == 0'' condition of termination.
    enum{ value = 1 };
};
int quartic_of_three = Pow<3, 4>::value;

我在维基百科上找到的。在这种情况下,intenum有什么区别吗?

EN

回答 1

Stack Overflow用户

发布于 2012-07-14 12:03:54

如果您尝试获取static const int的地址,则可能会有不同。在这种情况下,编译器将为static const int生成存储。您不能获取enum的地址,编译器将永远不会为它生成存储。

另见Template Metaprogramming - Difference Between Using Enum Hack and Static Const

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11483568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档