相关疑难解决方法(0)

g ++ -std = c ++ 0x出现意外的编译问题

我有一些编译问题在使用g ++ -std = c ++ 0x进行编译时将类型T的元素推回到向量.

这是一个最小的例子:

#include <vector>

using namespace std;

class A {
public:
    A() { }

    A& operator=(A &orig) {
        return *this;
    }
};

int main(int argc, char **argv) {
    A a;
    vector<A> b;
    A c = a; // This is fine
    b.push_back(a); // This is not, but only when compiling with -std=c++0x!
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

它使用g ++ -Wall -pedantic编译得很好,但是在使用g ++ -Wall -pedantic -std = c ++ 0x进行编译时会出现此错误:

 In file included from /usr/include/c++/4.4/vector:69,
                 from min.cpp:1:
/usr/include/c++/4.4/bits/vector.tcc: …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

8
推荐指数
1
解决办法
2226
查看次数

标签 统计

c++ ×1

c++11 ×1