C ++ Move构造函数不会编译

时间:2013-09-30 12:47:14

标签: c++ c++11 compiler-construction move

我有一个不幸的问题。我的GCC 4.6.3编译器拒绝编译我的移动构造函数。 在示例中使用“MemoryBlock(const MemoryBlock& other)”交换第6行将使其编译,但不使用下面的移动构造函数声明。好像编译器不知道C + 11,即使它应该使用4.6.3。正确?

#include <cstddef>

class MemoryBlock
{
public:
   MemoryBlock(MemoryBlock && other) //<----------- RAD 6.
    {
    }

private:
   size_t _length; // The length of the resource.
   int* _data; // The resource.
};

int main() {

}

编译器输出:

  

prog.cpp:6:28:错误:在'&amp;&amp;'标记之前预期','或'...'

     

prog.cpp:6:36:错误:构造函数无效;你可能的意思是'MemoryBlock(const MemoryBlock&amp;)'

     

make: * [slask]错误1

GCC版本:

  

g ++(Ubuntu / Linaro 4.6.3-1ubuntu5)4.6.3(Körfrånlabbsali skolan)

生成文件:

%.out:    %.cpp
    g++ -g -W -Wall -std=c++0x $*.cpp -o $*.out;

1 个答案:

答案 0 :(得分:1)

尝试-std = c ++ 11而不是-std = c ++ 0x。当您的编译器知道使用情况时,-std = c ++ 0x“关闭”这些新规则。