how to fix the error: ‘::max_align_t’?

how to fix the error: ‘::max_align_t’?

我收到错误

"/usr/include/c++/5/cstddef:51:11: error: ‘::max_align_t’ has not been declared using ::max_align_t; ^"

所以我应该更新库,因为我找到了这个解决方案:

"A workaround until libraries get updated is to include <cstddef> or <stddef.h> before any headers from that library."
我在 Ubuntu 终端上写了一些命令,例如:

bash $ sudo apt-get install apt-file
bash $ sudo apt-file update
bash $ apt-file search stddef.h

那么错误依旧存在。 谢谢

在出现这个编译错误的.cpp文件中需要添加

#include <cstddef>

在任何其他 headers 之前,例如

main.cpp(断)

#include <cstdio>

int main()
{
    using ::max_align_t;
    puts("Hello World");
    return 0;
}

尝试编译:

$ g++ -std=c++11 -o test main.cpp
main.cpp: In function ‘int main()’:
main.cpp:5:10: error: ‘::max_align_t’ has not been declared
  using ::max_align_t;
      ^

然后修复它:

main.cpp(固定)

#include <cstddef>
#include <cstdio>

int main()
{
    using ::max_align_t;
    puts("Hello World");
    return 0;
}

编译并运行它:

$ g++ -std=c++11 -o test main.cpp
$ ./test
Hello World

我在 CentOS 上使用 GNU C++ 4.9 编译了一些代码,但通过确保顶部位置#include(或使用较旧的 header 名称 stddef.h)并没有解决问题。

奇怪的是,我在编译器库的所有 header 文件中搜索了在有问题的 using 声明中声明的 max_aling_t 的全局定义。 . 并找到 none!会不会是在一些'内部编译的header?

所以我简单地 commented-out 标准 header 中的 "using ::max_align_t;" 行(确实不以这样做为荣)它解决了问题......代码是 运行...

如果有人能解释一下这个 max_align_t 的 meaning/impact 是什么?

我也注释掉了 /usr/include/c++/4.9/cstddef 中的 using ::max_align_t; 行,而代码是 运行,但我不知道这样做是否有任何后果.. .