从命令行编译时"error: expected expression",但不从 Xcode 编译时
"error: expected expression" when compiling from command line but not from Xcode
我分别用clang++
(700.1.76)和Xcode 7.1编译了以下代码片段。
#include <iostream>
#include <string>
using namespace std;
class Point {
private:
int x;
int y;
public:
Point(int x1 = 0, int y1 = 0) {
x = x1;
y = y1;
}
string display() {
return "(" + to_string(x) + ", " + to_string(y) + ")";
}
};
class Shape {
private:
Point bottomLeft;
Point upperRight;
public:
Shape(Point bottomLeft1, Point upperRight1) {
bottomLeft = bottomLeft1;
upperRight = upperRight1;
}
Point getBottomLeft() {
return bottomLeft;
}
};
int main(int argc, char const *argv[]) {
Point p1(1, 2);
Point p2(3, 4);
Shape s1(p1, p2);
Shape s2({1, 2}, {3, 4});
cout << s1.getBottomLeft().display() << endl;
cout << s2.getBottomLeft().display() << endl;
return 0;
}
在Xcode中,我得到的预期输出
(2, 1)
(2, 1)
但是使用clang++
,程序无法编译并抛出以下错误:
test.cpp:38:11: error: expected expression
Shape s2({1, 2}, {3, 4});
^
(对于{3, 4}
,同样的错误也会重复出现。)
这是怎么回事?
在调用clang++
时,我需要指定语言标准。
显然,任何高于c++11
的东西都可以。
相关文章:
- SFML在使用Xcode 11和macOS Catalina(zsh)编译后崩溃
- 我不能用C++编译Xcode库
- 将XCode升级到verison 11.1后,C++编译失败
- 某些C++标头在放入 Xcode 前缀/预编译标头时会中断构建
- C 11模板代码 - 无法在XCode中编译
- 尝试在终端(MacOSX)中编译两个.cpp文件(来自XCode)时"Duplicate symbol"
- XCode预编译标头中的C 语言的预处理器定义了什么?
- Xcode - 如何使用"-fexhaustive-register-search"进行编译 - 链接器崩溃需要
- C++静态库未在 Mac 上的 Xcode 中编译
- 如果标头位于预编译标头 xcode 中,则找不到默认模板参数
- 编译 c++ 代码时 xcode 上的线程
- 由于 LLVM 错误,Xcode 无法编译
- 在 xcode 中编译和链接 OpenCV 3.0.0 时出现问题
- 无法使用 Xcode 和终端在 Mac OS 上使用 OpenGL 库编译 c++ 文件
- Xcode 4.5.2 致命错误:预编译标头已被修改
- boost.log在使用Xcode预编译头时中断
- 用警告在G 上编译代码,但在Clang3.1(Xcode 4.3.3)上给出了相同代码的错误
- 在 Xcode 6 中运行 cpp-netlib - 编译但在运行时崩溃
- "Extra ';' " Xcode C++项目中的编译错误
- xCode正在编译旧的C++代码