1

I'm trying to run an example from Microsoft Docs on delegating constructors in C++. For small bits of code like this, I like to use VS Code, but when I use my usual make command in the terminal I get the error,

error: delegating constructors are permitted only in C++11

I do not get this error when I run the same code in Xcode.

Why can't I run this in the terminal? My Xcode stuff, including command line tools, is up to date so is there something else I'm missing?

Edit

If I enter g++ --version in the terminal I get,

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: x86_64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
MoogsDoog
  • 53
  • 4
  • 1
    When asking a question like this, you absolutely need to include information like how you're compiling your code. We don't know what "usual make command" is - or in this case more specifically, what flags you're passing to the compiler. It's guessable in this instance but generally when asking a question include as much relevant information as you can (obviously not several pages of context, but on unexpected compile errors the offending code and the exact details on how you're compiling are vital). – Cubic Jan 07 '22 at 20:37
  • Sorry, @Cubic I am still quite a noob when it comes to compilation. I haven't before had to write my own makefile. Usually I just use `make` without a makefile when compiling short programs [as recommended here](https://stackoverflow.com/questions/221185/how-to-compile-and-run-c-c-in-a-unix-console-mac-terminal) – MoogsDoog Jan 07 '22 at 21:19
  • You don't need to apologise for not knowing something, but for instance if you're compiling a file by typing `make something` without a Makefile just say exactly that that's what you're doing. In this case you might not have been aware but `make` is a whole buildsystem and can basically do pretty much _anything_ depending on how its configured, so just saying you use `make` isn't super helpful on its own. – Cubic Jan 09 '22 at 14:10
  • Will do and thank you, I do appreciate the help and feedback – MoogsDoog Jan 11 '22 at 19:13

1 Answers1

2

You need to add --std=c++11 to the g++ command line options in your Makefile. Visual Studio defaults to the latest possible C++ standard. gcc defaults to the earliest.

Tim Roberts
  • 48,973
  • 4
  • 21
  • 30
  • Thanks Tim, that worked! – MoogsDoog Jan 07 '22 at 21:05
  • The op is using Apple clang not gcc, the default c++ standard used by gcc varies by the version of gcc but is a fairly recent one but not necessarily the latest. Visual studio defaults to the latest stable version of the standard that it supports, not the very latest version (which can be enabled with `/std:c++latest`). Apple clang still defaults to c++98 for reasons only known by Apple – Alan Birtles Jan 07 '22 at 22:58