3

I'm trying to compile a project on my university's ssh server and I get the error:

Node.h:12: error: ‘nullptr’ was not declared in this scope

Chunk of code from my Node.h class:

template <typename T> 

struct Node{
    T data; 
    Node *leftChild; 
    Node *rightChild; 

    Node(const T & theData = nullptr, Node *left = nullptr, Node *right = nullptr);
    Node(T && theElement = nullptr, Node *left = nullptr, Node *right = nullptr);

    T getData(); 
}; 

The server runs on GCC version 4.4.7 and I'm compiling using the following command:

g++ -std=c++0x

^ I use this command for all of my projects for this class, and this is the first time I'm running into this issue. What can I try to resolve this?

5
  • 1
    Your compiler is old. Commented Feb 12, 2020 at 19:17
  • I know, I don't know why my school hasn't updated it in so long :( Commented Feb 12, 2020 at 19:18
  • nullptr came into being in C++11, see en.cppreference.com/w/cpp/language/nullptr Commented Feb 12, 2020 at 19:18
  • @hmp54 It seems your compiler does not support the literal nullptr. Instead use NULL. Commented Feb 12, 2020 at 19:19
  • With const T & theData = nullptr, your elements can only be pointers (or nullptr_t). I doubt that it's what you want – you probably want const T & theData = T() Commented Feb 12, 2020 at 19:35

1 Answer 1

3

According to https://gcc.gnu.org/projects/cxx-status.html#cxx11, the null pointer constant is a part of GCC 4.6+. You'll have to find a way around using the nullptr constant or update the GCC version(recommended).

Sign up to request clarification or add additional context in comments.

2 Comments

I can't update the GCC version since I'm working with my university's server. What's an alternative to nullptr and null? Both of them cause the same error.
@hmp54 did you try null or NULL? You could also just try = 0 as that (I believe) is the underlying logic of NULL. See here: cplusplus.com/reference/cstring/NULL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.