Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ &引用;错误:应为表达式“0”;从命令行编译而不是从Xcode编译时_C++_Xcode_Clang_Clang++ - Fatal编程技术网

C++ &引用;错误:应为表达式“0”;从命令行编译而不是从Xcode编译时

C++ &引用;错误:应为表达式“0”;从命令行编译而不是从Xcode编译时,c++,xcode,clang,clang++,C++,Xcode,Clang,Clang++,我分别使用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; } strin

我分别使用
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;
}
但是使用
clang++
,程序无法编译并抛出此错误:

test.cpp:38:11: error: expected expression
    Shape s2({1, 2}, {3, 4});
             ^
(对于
{3,4}
这件事,同样的错误也会重复。)


这是怎么回事?

调用
clang++
时,我需要指定语言标准


显然,任何高于
c++11
的操作都可以。

调用
clang++
时,我需要指定语言标准


显然,任何高于
c++11
的东西都可以。

这可能是您的clang版本的问题。它编译@NathanOliver-Hmm,使用那些标志编译my
clang
,但如果没有这些标志,它就不起作用。实际上,使用
-std=c++14
作为唯一的标志进行编译是可行的,但不指定
-std
会导致错误。那么,我猜,指定语言标准是很重要的?是的,要使它起作用,您需要至少有
std=c++11
,这可能是您的clang版本的问题。它编译@NathanOliver-Hmm,使用那些标志编译my
clang
,但如果没有这些标志,它就不起作用。实际上,使用
-std=c++14
作为唯一的标志进行编译是可行的,但不指定
-std
会导致错误。那么,我猜,指定语言标准是很重要的?是的,要使它起作用,您至少需要有
std=c++11
test.cpp:38:11: error: expected expression
    Shape s2({1, 2}, {3, 4});
             ^