C_plus_plus_0x11.cpp:
//c_plus_plus_0x11.cpp: Defines the entry point of the console application. //#include"stdafx.h"#include<Windows.h>#include<iostream>using namespacestd;classa{ Public: intAddintAintb) {returnA +b;} intSubintAintb) {returnAb;}};classD | Publica{ Public: //int sub (int a, int b) = delete;};int_tmain (intARGC, _tchar*argv[]) {A A; cout<<"5+2="<< A.add (5,2) <<Endl; cout<<"5-2="<< A.sub (5,2) << endl<<Endl; b b; cout<<"9+3="<< B.add (9,3) <<Endl; cout<<"9-3="<< B.sub (9,3) << Endl <<Endl; cout<<" Done"<<Endl; GetChar (); return 0;}
Operating effect:
To delete this line of code:
// int sub (int a, int b) = delete;
Recompile, the result is:
Visible, delete can be used to delete a class from the base class inherited functions, heard can be used to delete the copy constructor, try again below.
C_plus_plus_0x11.cpp:
//c_plus_plus_0x11.cpp: Defines the entry point of the console application. //#include"stdafx.h"#include<Windows.h>#include<iostream>using namespacestd;classa{ Public: A (intAintb) {a_ = A; b_ =b;} intAdd () {returnA_ +B_;} intSub () {returnA_-B_;} //A (const a&) = delete; //no copy inta_{}; intb_{};};int_tmain (intARGC, _tchar*argv[]) {A A (5,2); cout<<"5+2="<< A.add () <<Endl; cout<<"5-2="<< a.sub () << endl<<Endl; A b=A; cout<< B.a_ <<"+"<< b.b_ <<"="<< B.add () <<Endl; cout<< B.a_ <<"-"<< b.b_ <<"="<< b.sub () <<Endl; cout<<" Done"<<Endl; GetChar (); return 0;}
Operating effect:
To delete this line of code:
// A (const a&) = delete; // no copy
Recompile:
It is estimated that delete can be used to remove a class from a base class that inherits (such as the A.sub function) and this class implicitly exists (such as a copy constructor) function.
Data Source:
C++11 FAQ Http://www.stroustrup.com/C++11FAQ.html#default
Finish.
C++0x11 new features: delete delete function