首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++移动构造函数不会编译

C++移动构造函数不会编译
EN

Stack Overflow用户
提问于 2013-09-30 12:47:14
回答 1查看 853关注 0票数 0

我有个不幸的问题。我的GCC 4.6.3编译器拒绝编译我的移动构造函数。将示例中的第6行与" MemoryBlock (const MemoryBlock& other)“交换将使其编译,但不使用下面的move构造函数声明。编译器似乎不知道C+11,尽管它应该使用4.6.3。对吗?

代码语言:javascript
复制
#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:错误:预期“,”或“.”在“&&”令牌之前 prog.cpp:6:36:错误:无效构造函数;您可能是指“MemoryBlock(constructor&)” 制造:* slask错误1

GCC版本:

g++ (Ubuntu/Linaro 4.6.3 -1 ubuntu5)4.6.3(K R Fr N labbsal I skolan)

makefile:

代码语言:javascript
复制
%.out:    %.cpp
    g++ -g -W -Wall -std=c++0x $*.cpp -o $*.out;
EN

回答 1

Stack Overflow用户

发布于 2015-06-15 18:10:41

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19094678

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档