Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Error 'nullptr was not declared in this scope' in Eclipse IDE

I am running Eclipse Helios and I have g++-4.6 installed. Hope I am not wrong that g++4.6 implements C++ 11 features. I have created a C++ project which uses the nullptr and auto keywords. The build gives the following errors:-

../{filename}.cpp:13:13: error: ‘nullptr’ was not declared in this scope  ../{filename}.cpp:14:2: warning: ‘auto’ will change meaning in C++0x; please remove it [-Wc++0x-compat] 

Actually it was building fine until yesterday. I am getting these from nowhere today. Please help me solve this problem.

like image 555
Higher-Kinded Type Avatar asked Apr 05 '12 17:04

Higher-Kinded Type


People also ask

What is nullptr in C?

The nullptr keyword represents a null pointer value. Use a null pointer value to indicate that an object handle, interior pointer, or native pointer type does not point to an object.

What does nullptr stand for?

According to cppreference, nullptr is a keyword that: denotes the pointer literal. It is a prvalue of type std::nullptr_t . There exist implicit conversions from nullptr to null pointer value of any pointer type and any pointer to member type.

Is null and nullptr the same?

nullptr is a keyword that can be used at all places where NULL is expected. Like NULL, nullptr is implicitly convertible and comparable to any pointer type. Unlike NULL, it is not implicitly convertible or comparable to integral types.

What is the value of null or nullptr?

nullptr vs NULL NULL is 0(zero) i.e. integer constant zero with C-style typecast to void*, while nullptr is prvalue of type nullptr_t which is integer literal evaluates to zero.


1 Answers

According to the GCC page for C++11:

To enable C++0x support, add the command-line parameter -std=c++0x to your g++ command line. Or, to enable GNU extensions in addition to C++0x extensions, add -std=gnu++0x to your g++ command line. GCC 4.7 and later support -std=c++11 and -std=gnu++11 as well.

Did you compile with -std=gnu++0x ?

like image 179
Rob I Avatar answered Sep 21 '22 22:09

Rob I