有人正在编译使用C++11标准的Qt程序,他们遇到了这个错误(Mac OS X / gcc)。我知道我可以声明它,但它不应该已经在<cstddef>
吗?
./collectable_smartptr.hpp:54:33: error: no type named 'nullptr_t' in namespace 'std'
void operator=(std::nullptr_t &null)
这段代码在Windows和Linux上运行得很好,我在Mac上看到它。
Mac是i386-apple-darwin11.3.0,编译器是:
$ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.2.0
Thread model: posix
g ++选项(部分)是-c -pipe -std=c++11 -O2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_USE_QSTRINGBUILDER -DQT_NO_DEBUG -DQT_WEBKIT_LIB -DQT_XML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED
这是正常的吗?或者在Mac上需要做些什么才能使C ++ 11工作?
答案 0 :(得分:5)
明确包含内容总是更好,所以,我会将其添加到代码中:
#include <cstddef>
如果这不起作用,则意味着您的系统存在根本问题,即:
作为一种快速而讨厌的解决方法,您当然可以自己进行typedef,如下所示:
namespace std {
typedef decltype(nullptr) nullptr_t;
}
或没有std
,但这真的应该是最后的手段,通常这意味着你做错了。
答案 1 :(得分:2)
使用#include <cstddef>
无法解决问题,但插入
namespace std
{
typedef decltype(nullptr) nullptr_t;
}
显然有助于解决这个问题,尽管我仍然不明白为什么它真的需要。
PS:鉴于我不是计算机的所有者,我无法进行任何进一步的调查,请参阅https://github.com/huggle/huggle3-qt-lx/issues/101了解详情
答案 2 :(得分:0)
当我将sstream
包含在命名空间std
中时,我遇到了同样的问题:
namespace std {
// Some #ifdefs and so on
// quite hidden
#include <sstream>
}
将include移出命名空间解决了问题:
#include <sstream>
namespace std {
}
编译器:没有C ++ 11的Apple LLVM版本8.0.0(clang-800.0.38)。