g++ 'nullptr' was not declared in this scope

29,444

Try in c++11 mode:

g++ -std=c++11 -I../includes bst.cpp
Share:
29,444
nikhil
Author by

nikhil

I'm an open source enthusiast and an avid programmer and a Manchester United fan. Based out of New Jersey these days, exploring the world and learning new things. #SOreadytohelp

Updated on July 25, 2020

Comments

  • nikhil
    nikhil almost 4 years

    I'm using gcc-4.7.1 on windows 8 Release Preview with 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)
    

    When I try to compile a small code snippet,

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

    I get this error,

    $ 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
    

    I'm not able to use either NULL or nullptr, do I need to include some header files?