繁体   English   中英

从命令行而不是从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都可以。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM