如何使用默认和删除的函数C++; 最近我试图了解C++ 11中的缺省和删除函数,我在下面写了示例代码。当我尝试运行时,它会显示:

如何使用默认和删除的函数C++; 最近我试图了解C++ 11中的缺省和删除函数,我在下面写了示例代码。当我尝试运行时,它会显示:,c++,c++11,C++,C++11,错误C2065:“默认”:未声明的标识符 守则: #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);

错误C2065:“默认”:未声明的标识符

守则:

#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;
}
#包括“stdafx.h”
#包括
#包括
使用名称空间std;
结构A
{
智力年龄;
A(int x):年龄(x){};
A()=默认值;
};
int _tmain(int argc,_TCHAR*argv[]
{
测试(10);

无法使用MSVC++编译器默认和删除函数的Visual Studio。您需要使用类似于G++的工具。

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


检查可用功能的列表。您将看到默认和删除的函数尚不可用。

使用支持C++11的编译器或启用相同的设置。我使用Visual Studio 2012 RCis是否有方法自定义VSVC++编译器以使用MinGW G++?不,您不能告诉编译器使用其他编译器。如何你可以告诉visual studio使用不同的编译器。我发现了这个()。不过我不明白你为什么要使用visual studio。