gcc - g++ 'nullptr' 未在此范围内声明

标签 gcc null g++

我在 Windows 8 Release Preview 上使用 gcc-4.7.1 和 git-bash。

$ g++ -v
Using built-in specs.
COLLECT_GCC=c:\Users\nikhil bhardwaj\mingw64\bin\g++.exe
COLLECT_LTO_WRAPPER=c:/users/nikhil bhardwaj/mingw64/bin/../libexec/gcc/x86_64-w
64-mingw32/4.7.1/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: /home/drangon/work/mingw-w64-dgn/source/gcc/configure --host=x8
6_64-w64-mingw32 --target=x86_64-w64-mingw32 --disable-nls --enable-languages=c,
c++,objc,obj-c++ --with-gmp=/home/drangon/work/mingw-w64-dgn/build/for_target --
enable-twoprocess --disable-libstdcxx-pch --disable-win32-registry --prefix=/hom
e/drangon/work/mingw-w64-dgn/target --with-sysroot=/home/drangon/work/mingw-w64-
dgn/target
Thread model: win32
gcc version 4.7.1 20120524 (prerelease) (GCC)

当我尝试编译一个小代码片段时,

using namespace std;
struct node
{
    int data;
    node *left, *right;
};
node *newNode(int data)
{
    node *node = new (struct node);
    node->data = data;
    node->left = nullptr;
    node->right = NULL;
    return node;
}

我收到此错误,

$ g++ -I../includes bst.cpp
bst.cpp: In function 'node* newNode(int)':
bst.cpp:13:18: error: 'nullptr' was not declared in this sc
bst.cpp:14:19: error: 'NULL' was not declared in this scope

我无法使用 NULLnullptr,我需要包含一些头文件吗?

最佳答案

在 C++11 模式下尝试:

g++ -std=c++11 -I../includes bst.cpp

关于gcc - g++ 'nullptr' 未在此范围内声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11616539/

相关文章:

python - 从 Python 中返回 include 和 runtime lib 目录

适用于 OS X 的带有 openmp 的 Python C 扩展

c++ - 输入奇数时打印空字符

g++ - 无法识别的命令行选项 ‘-std=c++11’

multithreading - gcc参数: -pthread.它是做什么的?

c - 从 fgets() 输入中删除换行符

java - null 指向任何内容是什么意思,为什么要使用 null?

powershell - 是否可以在 PowerShell 中的 bool[] 中包含 [Nullable[bool]]

c++ - 如何在 C++ 文件中查找特定库使用的函数

c++ - 无法编译 Crow 示例 - boost/optional.hpp : No such file or directory