I compiled the following code snippet with clang++
(700.1.76) and Xcode 7.1 separately.
#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;
}
In Xcode, I get the expected output of
(2, 1)
(2, 1)
but using clang++
, the program fails to compile and throw this error:
test.cpp:38:11: error: expected expression
Shape s2({1, 2}, {3, 4});
^
(This same error is repeated for the {3, 4}
thing as well.)
What's going on here?
答案 0 :(得分:0)
我需要在调用clang++
时指定语言标准。
显然,c++11
以上的任何内容都可以。