如何使用默认和删除的函数C++

Blo*_*aRd 2 c++ c++11

我最近尝试了解C++ 11中的默认和删除函数,我在下面编写了示例代码.当我尝试运行时说:

错误C2065:'default':未声明的标识符

代码 :

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

struct A
{
    int age;

    A(int x): age(x){};
    A() = default;

};

int _tmain(int argc, _TCHAR* argv[])
{
    A test(10);
    cout << test.age << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Jos*_*uel 7

您似乎正在使用Microsoft Visual Studio.很抱歉,即使在新版本VC11中,Microsoft编译器也不允许使用这种新语法.

此处查看可用功能列表.您将看到默认和已删除的功能尚不可用.