错误:'INT32_MAX'未在此作用域中声明 [英] error: 'INT32_MAX' was not declared in this scope
本文介绍了错误:'INT32_MAX'未在此作用域中声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到错误
错误:'INT32_MAX'未在此范围内声明
但我已包括
#include< stdint.h> (gcc)4.1.2 20080704(Red Hat 4.1.2-GCC)编译这个的时候, 44)使用命令 g ++ -m64 -O3 blah.cpp
pre>
我需要做任何其他事情来获得这个编译?或者是另一个C ++方式获取常量 INT32_MAX $
解决方案 / div> #include< cstdint> //或&stdint.h>
#include< limits>
std: :numeric_limits< std :: int32_t> :: max();
注意< cstdint>
是C ++ 11标题,< stdint.h>
是C标题,
以下代码适用于C ++ 11。
#include< iostream>
#include< limits>
#include< cstdint>
struct X
{
static const std: :int32_t i = std :: numeric_limits< std :: int32_t> :: max();
};
int main()
{
switch(std :: numeric_limits< std :: int32_t> :: max()){
case std :: numeric_limits< std :: int32_t> :: max():
std :: cout<< 这段代码的工作原理感谢constexpr\\\
;
break;
}
return EXIT_SUCCESS;
}
http://coliru.stacked-crooked.com/a/4a33984ede3f2f7e
I'm getting the error
error: 'INT32_MAX' was not declared in this scope
But I have already included
#include <stdint.h>
I am compiling this on (g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44) with the command
g++ -m64 -O3 blah.cpp
Do I need to do anything else to get this to compile? or is there another C++ way to get the constant "INT32_MAX
"?
Thanks and let me know if anything is unclear!
解决方案 #include <cstdint> //or <stdint.h>
#include <limits>
std::numeric_limits<std::int32_t>::max();
Note that <cstdint>
is a C++11 header and <stdint.h>
is a C header, included for compatibility with C standard library.
Following code works, since C++11.
#include <iostream>
#include <limits>
#include <cstdint>
struct X
{
static const std::int32_t i = std::numeric_limits<std::int32_t>::max();
};
int main()
{
switch(std::numeric_limits<std::int32_t>::max()) {
case std::numeric_limits<std::int32_t>::max():
std::cout << "this code works thanks to constexpr\n";
break;
}
return EXIT_SUCCESS;
}
http://coliru.stacked-crooked.com/a/4a33984ede3f2f7e
这篇关于错误:'INT32_MAX'未在此作用域中声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文