警告 C4003 以及错误 C2589 和 C2059 在:x = std::numeric_limits<int

2023-07-02C/C++开发问题
1

本文介绍了警告 C4003 以及错误 C2589 和 C2059 在:x = std::numeric_limits<int>::max();的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

此行在一个小型测试程序中正常工作,但在我想要的程序中,我收到以下编译器投诉:

This line works correctly in a small test program, but in the program for which I want it, I get the following compiler complaints:

#include <limits>

x = std::numeric_limits<int>::max();

c:...x.cpp(192) : warning C4003: not enough actual parameters for macro 'max'
c:...x.cpp(192) : error C2589: '(' : illegal token on right side of '::'
c:...x.cpp(192) : error C2059: syntax error : '::'

我得到了相同的结果:

#include <limits>
using namespace std;

x = numeric_limits<int>::max();

为什么将 max 视为宏 max(a,b);?

Why is it seeing max as the macro max(a,b); ?

推荐答案

当包含定义 minmax 宏的 Windows 标头时,通常会发生这种情况.如果您使用的是 Windows 标头,请将 #define NOMINMAX 放入您的代码中,或者使用等效的编译器开关进行构建(即,对于 Visual Studio,使用 /DNOMINMAX).

This commonly occurs when including a Windows header that defines a min or max macro. If you're using Windows headers, put #define NOMINMAX in your code, or build with the equivalent compiler switch (i.e. use /DNOMINMAX for Visual Studio).

请注意,使用 NOMINMAX 构建会禁止在整个程序中使用宏.如果需要使用 minmax 操作,请使用 std::min()std::max() 来自 标头.

Note that building with NOMINMAX disables use of the macro in your entire program. If you need to use the min or max operations, use std::min() or std::max() from the <algorithm> header.

这篇关于警告 C4003 以及错误 C2589 和 C2059 在:x = std::numeric_limits<int>::max();的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&amp;()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6