【问题标题】:Including windows.h causes an error [duplicate]包含 windows.h 会导致错误 [重复]
【发布时间】:2015-12-22 09:00:38
【问题描述】:

这很奇怪,我有一个我一直在构建的课程,目前我的文件顶部有这个:

#pragma once
#include <cstdint>
#include <cstring>
#include <string>
#include <limits>

现在我需要将 windows.h 添加到组合中,但只要我这样做,我就会在这一行得到“错误:预期的标识符”:

inline uint32_t Hash2(std::string &Key) {
    return (MurMur3::x86_32(Key.c_str(), Key.size(), 2) % (std::numeric_limits<uint32_t>::max() - 1)) + 1;
}

如果重要,红线会出现在 ::max 下方。至于函数本身,它应该使用 murmur3 让我得到一个不为 0 的哈希。

如果我删除

std::numeric_limits<uint32_t>::max()

并将其替换为常量 4294967295

然后它又可以正常工作了。

我不明白为什么会这样。有人知道吗?

【问题讨论】:

  • #undef min 和 #undef max
  • 那行得通……为什么?
  • 因为 windows 是邪恶的 :)

标签: c++ windows visual-studio-2013


【解决方案1】:

Windows.h 有一个非常糟糕的习惯,即在其中定义宏。特别是,它定义了最小值和最大值。你需要取消这些。

【讨论】:

    猜你喜欢
    • 2020-06-07
    • 2016-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    相关资源
    最近更新 更多