为什么包含Windows.h时std :: min失败? [英] Why is std::min failing when windows.h is included?

查看:108
本文介绍了为什么包含Windows.h时std :: min失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <algorithm>
#include <Windows.h>

int main()
{
    int k = std::min(3, 4);
    return 0;
}

如果包含Windows.h,Windows在做什么?我无法在Visual Studio 2005中使用 std :: min 。错误消息是:

What is windows doing if I include Windows.h? I can't use std::min in visual studio 2005. The error message is:

error C2589: '(' : illegal token on right side of '::'
error C2059: syntax error : '::'


推荐答案

windows.h 头文件(或更正确地说,依次包含的 windef.h )具有 min max

The windows.h header file (or more correctly, windef.h that it includes in turn) has macros for min and max which are interfering.

在包含它之前,您应该 #define NOMINMAX

You should #define NOMINMAX before including it.

这篇关于为什么包含Windows.h时std :: min失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆