macOS:Apple clang 版本 13 在终端中出现 C++11 编译错误,但在 Xcode 中却没有

macOS: C++11 Compilation Error with Apple clang Version 13 In Terminal but not In Xcode

我正在尝试 运行 an example from Microsoft Docs 关于 C++ 中的委托构造函数。对于像这样的小代码,我喜欢使用 VS Code,但是当我在终端中使用我常用的 make 命令时,我得到了错误,

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

当我 运行 Xcode 中的相同代码时,我没有收到此错误。

为什么我不能在终端中 运行 这个?我的 Xcode 内容(包括命令行工具)是最新的,所以我还缺少其他内容吗?

编辑

如果我在我得到的终端中输入 g++ --version

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

您需要将 --std=c++11 添加到 Makefile 中的 g++ 命令行选项。 Visual Studio 默认为最新的 C++ 标准。 gcc 默认为最早的。