????????????????????????????????????????????麯?????????? delete ?????????????????????????????????????????????????????????????????????????????й?????????????????????????????????????麯????????????????????????? X ???????????????????磺
?????嵥 8
????class X {
????public:
????virtual ~X(){};     // ?????????????????
????private:
????int x;
????};
????class Y: public X {
????private:
????int y;
????};
????int main(){
????X* x = new Y;
????delete x;
????}
???????嵥 8 ?У????????????????? X ???????????????????????? delete ????????????????????????? x ????????????????????? Y ????????????????????????????????????? X ???????????????????????????????????????????????й???
????????????嵥 8 ?У???????????????д??????鹹????????壨???o?????????????????????????????????????????????????????????????????????Ч??????????????????????????????
????????????????????????????????????????????? defaulted ??????????????????????????????ú??????????????塣???磺
?????嵥 9
????class X {
????public:
????virtual ~X()= defaulted; // ????????????? defaulted ??????????
????private:
????int x;
????};
????class Y: public X {
????private:
????int y;
????};
????int main(){
????X* x = new Y;
????delete x;
????}
???????嵥 9 ?У?????????????????????????? virtual X::X(){}???ú?????????????????????????????и??????????Ч???
????Deleted ????
????????????

???????? C++ ???????????????????????????????????????????????????????????????????????????????????????????????????????翽???????????????????????????????磺
?????嵥 10
????class X{
????public:
????X();
????};
????int main(){
????X x1;
????X x2=x1;   // ??????????????????????????????????
????X x3;
????x3=x1;     // ?????????????????????????????????????
????}
???????嵥 10 ?У???????????????????д?????????????????????????????????????????????????????????????????????????????????????????????????????Щ???????????????μ?????????Щ????£??????????????????????????????????????????????????????????????????????????????????????????????????????????????
????Deleted ?????????
???????????ó?????????????????????C++11 ???????????????????deleted ????????????????????????????“=delete;”??????ú??????á????磬?????????? X ???????????????????????????????? deleted ?????????????? X ?????????????????
?????嵥 11
????class X{
????public:
????X();
????X(const X&) = delete;  // ??????????????? deleted ????
????X& operator = (const X &) = delete; // ?????????????????? deleted ????
????};
????int main(){
????X x1;
????X x2=x1;   // ????????????????????
????X x3;
????x3=x1;     // ???????????????????????
????}
???????嵥 11 ?У?????????????????????????????????????????????????????????????????? X ?????????????????????????????????????????????????????????????????????????????????????????????????????????? X ????κο????????????????????????????????????????????????????
????Deleted ??????????
????Deleted ?????? C++11 ?????????????????????deleted ?????????????? 2 ?????

????Deleted ???????÷??????
????Deleted ??????????????????????Щ????????????????????????????????????嵥 12 ?У??????? X ?????????????????? double ??????????????????????????????? int ??????????????????????????? int ??????????????????? deleted ??????
?????嵥 12
????class X{
????public:
????X(double);
????X(int) = delete;
????};
????int main(){
????X x1(1.2);
????X x2(2); // ????????????? int ????????????????????
????}
????Deleted ??????????????????????Щ???????????? new ?????????????????????洢???????????????磺
?????嵥 13
????#include
????using namespace std;
????class X{
????public:
????void *operator new(size_t) = delete;
????void *operator new[](size_t) = delete;
????};
????int main(){
????X *pa = new X;  // ????new ????????????
????X *pb = new X[10];  // ????new[] ????????????
????}
?????????????????????????????????? deleted ????????????????????????????????????????deleted ????????????????inline?????壬??????????????out-of-line?????塣???磺
?????嵥 14
????class X {
????public:
????X(const X&);
????};
????X::X(const X&) = delete;   // ????deleted ????????????????????????????
??????? defaulted ????????漲???????????????????????????? defaulted ?????????? deleted ???????????д??????????????????????????????????????? deleted ?????????磺
?????嵥 15
????int add (int??int)=delete;
????int main(){
????int a?? b;
????add(a??b); // ???????? add(int?? int) ??????
????}
?????????????????嵥 15 ?У???? add(int?? int)???????????????????????????????壬???ú???????????á????????????? add ??????Ч????????????????????????????????ú?????????????????????????????????????????? deleted ?????????????????????磺
?????嵥 16
????#include <iostream>
????using namespace std;
????int add(int??int) = delete;
????double add(double a??double b){
????return a+b;
????}
????int main(){
????cout << add(1??3) << endl;    // ?????????? deleted ???? add(int?? int)
????cout << add(1.2??1.3) << endl;
????return 0;
????}
??????????
????????????????? C++11 ?????? defaulted ?? deleted ?????????????????? C++ ???е????? default ?? delete ?????????????????????????μ???????巽??????????????? =default ?? =delete????????????????????????? defaulted ????????????????????????ú?????????????????塣?????????????? deleted ??????????????Щ??????????????????????Defaulted ?? deleted ????????????????????????? C++ ????????????м????????