移动构造函数 - 默认构造函数VS 2013的无效类型 [英] Move Constructor - invalid type for defaulted constructor VS 2013

查看:816
本文介绍了移动构造函数 - 默认构造函数VS 2013的无效类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读关于移动构造函数,我在VS 2013 ...

这个代码。

  class Student 
{
unique_ptr< string> pName_;

public:
学生(字符串名称):pName_(新字符串(名称)){}
〜Student(){}
学生(学生& )= default; //这里我得到错误。
void printStudentName(void){cout< * pName_<< endl }
};

int main(void)
{
vector< Student>人;

学生p =学生(Nishith);
persons.push_back(std :: move(p));
persons.front()。printStudentName();

return 0;
}

我得到 Student :: Student ;&):不是一个特殊的成员函数,可以默认当我试图编译它...



因为VS2013编译器不支持默认的移动构造函数。

$

b
$ b

请参阅下面的注意事项从MSDN


Visual Studio不支持默认移动构造函数或
移动赋值操作符作为C ++ 11标准强制。有关更多
信息,请参阅
的默认和已删除的函数部分支持C + +11功能(现代
C ++)



I was reading regarding move constructor and I did this code in VS 2013...

class Student
{
    unique_ptr<string> pName_;

public:
    Student(string name) : pName_(new string(name)) { }
    ~Student() { }
    Student(Student&&) = default;  // Here I get the error.
    void printStudentName(void) { cout << *pName_ << endl; }
};

int main(void)
{
    vector<Student> persons;

    Student p = Student("Nishith");
    persons.push_back(std::move(p));
    persons.front().printStudentName();

    return 0;
}

I get the "Student::Student(Student&& ) : is not a special member function which can be defaulted" when I tried to compile it...

Can anyone explain me why I am getting this error?

解决方案

Because the VS2013 compiler doesn't support defaulted move constructors.

See the following note from MSDN:

Visual Studio does not support defaulted move constructors or move-assignment operators as the C++11 standard mandates. For more information, see the Defaulted and Deleted functions section of Support For C++11 Features (Modern C++).

这篇关于移动构造函数 - 默认构造函数VS 2013的无效类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆