g++ 'nullptr' n'a pas été déclarée dans ce champ d'application

Je suis en utilisant gcc-4.7.1 sur windows 8 Release Preview avec 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)

Lorsque j'essaie de compiler un petit extrait de code,

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;
}

J'obtiens cette erreur,

$ 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

Je ne suis pas en mesure d'utiliser soit NULL ou nullptr, dois-je avoir besoin d'inclure des fichiers d'en-tête?

NULL est définie dans un certain nombre de C-legacy-têtes (<cstddef> est probablement le préféré d'en-tête dans le C++). Il n'est pas un mot clé qui est définie automatiquement.

OriginalL'auteur nikhil | 2012-07-23