gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:30:30 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com