为什么是mingw 4.4说< random>需要c ++ 0x? [英] Why is mingw 4.4 saying <random> needs c++0x?

查看:142
本文介绍了为什么是mingw 4.4说< random>需要c ++ 0x?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么说,除了明显的答案。还有我如何解决这个问题,我不想添加c ++ 11代码到这个项目。

  #include < random> 

mingw 4.4(QTSDK附带的版本,不使用QT库,只是QT Creator) p>

此文件需要编译器和库支持即将到来的\
ISO C ++标准C ++ 0x。此支持目前是实验性的,必须使用-std = c ++ 0x或-std = gnu ++ 0x编译器选项启用\

解决方案

< random> 头仅添加到C ++ 0x中的c ++标准。如果您尝试在C ++ 98模式下使用< random> ,标准库实现器会将预处理器指令错误地输出,原因有两个:



如果头文件利用了新的C ++ 0x语言特性,那么它在默认的C ++ 98模式下根本不起作用。 C ++ 0x错误消息是这样,所以你会明白为什么它不工作,而不是要弄清楚未知关键字汤和其他错误消息的意义。



如果头文件不需要任何新的C ++ 0x语言功能,那么C ++ 0x错误消息是存在的,所以你不会不小心使用它认为它在C ++ 98。如果你这样做,然后有人试图编译你的代码在一个C ++ 98只有编译器没有装运< random> 头所有(例如,你打算通过限制自己到C ++ 98支持的旧版本的GCC),他们会很疯狂。


Why is it saying that other than the obvious answer. Also how can I work around this, I don't want to add c++11 code to this project.

#include <random>

mingw 4.4 ( version that's shipped with QTSDK, not using QT Libraries though, just QT Creator )

This file requires compiler and library support for the upcoming \ ISO C++ standard, C++0x. This support is currently experimental, and must be \ enabled with the -std=c++0x or -std=gnu++0x compiler options.

解决方案

The <random> header was only added to the c++ standard in C++0x. The standard library implementers put in a preprocessor directive to error out if you try to use <random> in C++98 mode, for one of two reasons:

If the header file takes advantage of new C++0x language features, it wouldn't work at all in the default C++98 mode. The C++0x error message is there so that you'd understand why it didn't work, rather than having to figure out the meaning of soup of "unknown keyword" and other error messages.

If the header file doesn't require any new C++0x language features, then the C++0x error message is there, so that you wouldn't accidentally use it thinking it was available in C++98. If you were to do that, and then somebody else tried to compile your code on a C++98-only compiler that didn't ship the <random> header at all (e.g. an older version of GCC that you intended to support by restricting yourself to C++98), they'd be quite mad.

这篇关于为什么是mingw 4.4说&lt; random&gt;需要c ++ 0x?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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