I'd like to use nullptr instead of NULL, but when I compile using G++:
g++ main.cpp renderer.cpp -I c:\some\includedir -o game
I get the following compiler warning (and error):
1 2 3
Warning: "non-static data member initializers only available with -std=c++11 or -std=gnu+11""Error: 'nullptr' was not declared in this scope"
I researched and understand that nullptr was added to C++ in 2011 and I need to use the suggested flag (-std=c++11 or std=gnu+11), but if I use either of them like:
g++ -std=c++11 main.cpp renderer.cpp -I some/includedir -o game
...I get a Windows Error Alert box saying:
"The Procedure entry point __gxx_personality_v0 could not be located in dynamic link library"
..and the program fails to compile. Does anybody have any idea what I'm doing wrong or how to properly compile a C++ program using the latest version of C++ so nullptr works?
What I'm using:
- Compiling program in the Windows command line
- editing code in VIM
- OS: Windows 8.1
- GCC Version: 4.9.3
Hi,
> How to properly compile a C++ program using the latest version of C++ so nullptr works
The word nullptr is normally supposed to have a special blue color like that of a keyword. However, if it does not happen in your case, you may try this :
@Duoas
I simply think nullptr is too much of a simple concept. Why do they have to go that far as to use std = c++11 or std=gnu + 11 at the command line so that the complier supports that trivial keyword?
If possible, try to always have the latest compilers - gcc is at version 6.1 currently. Not sure what the story is in terms of using them with Windows, I gather one has to use whatever the latest version of MinGW is. I am a Linux guy, so I am not up with all the details on that :+)
Edit: Apparently MinGW GCC 6.10 for Windows does exist :+)
Good Luck !!
@closed account 5a8Ym39o6 (696)
#define nullptr 0
No, that is wrong. nullptr was invented to avoid the problems encountered with using NULL with a pointer type. What you have done is provide a definition of NULL with a different name. Note that nullptr is a prvalue.
nullptr has the type std::nullptr_t Use of the c++11 standard or greater is necessary because those things are defined there.
Yep, another good reason to upgrade to the latest version, one could leave out the -std= unless they wanted to do C++17 .... in which case the normal method of -std=c++17 or -std=c++1z plus some other flags for concepts etc.