Blood-HaZaRd
Blood-HaZaRd

Reputation: 2138

How to use defaulted and deleted functions C++

I recently tried to learn about the defaulted and deleted functions in C++ 11 and i wrote the sample code below. When I try to run it says :

error C2065: 'default' : undeclared identifier

the Code :

#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;
}

Upvotes: 2

Views: 3736

Answers (2)

Jos&#233; Manuel
Jos&#233; Manuel

Reputation: 1096

It seems that you are using Microsoft Visual Studio. I'm sorry but the Microsoft compiler doesn't allow this new syntax even in the new version VC11.

Check the list of the available features here. You will see that Defaulted and deleted functions isn't yet available.

Upvotes: 7

Publius
Publius

Reputation: 1224

Visual Studio with the MSVC++ compiler does not support defaulted and deleted functions. You'll need to use something like MinGW's G++.

Upvotes: 1

Related Questions