1 #include <cstdlib> 2 #include <iostream> 3 4 enum { SIZE_PER_CHUNK = ((1<<16) / sizeof(unsigned)) }; 5 6 class TrueType {} ; 7 class FalseType {} ; 8 9 template< std::size_t V,bool B = (((V) & ((V) - 1)) == 0) > class IsPowerOfTwo_;10 template< std::size_t V > class IsPowerOfTwo_< V,true > : public TrueType {};11 template< std::size_t V > class IsPowerOfTwo_< V,false > : public FalseType {};12 13 typedef IsPowerOfTwo_< SIZE_PER_CHUNK > IsPowerOfTwo; 141516 int main() {17 IsPowerOfTwo p2;18 19 std::cout << "Hello World!" << std::endl;20 return 0;21 }
以下代码给出了编译器警告(gcc 4.6.2,/ project / dfttools / compile / lnx-x86 / gcc-4.6.2):
warning: suggest parentheses around ‘-‘ in operand of ‘&’ [-Wparentheses]
警告指向第13行,但它可能与第9行中的表达式有关.
有解决方案吗
解决方法 看起来像编译器错误给我.就好像编译器从默认B值中删除不需要的括号,然后它会引发警告本身.解决方法:
template<size_t V> struct IsPowerOfTwo_Helper{ enum { value = V & (V - 1) };};template< std::size_t V,bool B = IsPowerOfTwo_Helper<V>::value == 0 > class IsPowerOfTwo_;总结
以上是内存溢出为你收集整理的c – 有关模板的编译器警告全部内容,希望文章能够帮你解决c – 有关模板的编译器警告所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)