By checking my g++ version with g++ --version, it is also 4.2.1. By reading other responses online, installing Xcode seems to be the correct way to install g++. I have the latest version of Xcode, but when I type:
g++ test.cpp -o test
If my cpp file has a constructor like:
Constructor() = default;
I get warning saying that default is a 2011 extension.
I use makefiles for my projects with multiple cpp files and such, but when I only have one main cpp file I tend to use the g++ terminal command because it's easier for me to just type it up and run the program to check outputs. It's much easier to run my commands through terminal than running my code through cpp.sh because it cpp.sh crashes quite a bit, and running on my own machine compiles and builds faster than the online compiler.
XCode 8.2.1 which is the latest for an MBPro (and probably everything else Apple-like) comes automatically with C++11, C++14 and each is selectable via the properties of each separate project. Same goes for warnings level selections.
I have Xcode, but I prefer to run my program through terminal.
Running the program (executable) in terminal has nothing to do with it as far as I can understand from your question.
To update your Xcode just download/update it ... https://developer.apple.com/xcode/ You might have to register as a developer or use existing Apple ID which is all free including the download.
@Pattako:
You're right that gcc(1) is a C compiler, but GCC (in all caps) is the GNU Compiler Collection, which contains both gcc(1) and g++(1), the binutils, and a bunch of other optional utilities and compilers which should be updated concurrently.
@OP:
Does the CFLAGS trick work for you?
I am unsure how to update your compiler. I have no experience with Apple's computers. You may have to build it; I did this last month, but I run Linux.