• 欢迎光临~

=delete,=default

开发技术 开发技术 2022-07-24 次浏览
  • [= delete]

using private constructor:

application-1:

点击查看代码
#include<iostream>

using namespace std;

class B;
class A {
friend class B;
private:
    A() {};
public:
    void print() {
        cout << " i am an object of class A"
        << endl;
    }

};
class B {
public:
    void print() {
        //note: declared private here
        A().print();
    }
};


int main() {
    //error:A::A()' is private within this contex
    //A a;
    B().print();
    return 0;
}

application-2:sigleton

  • [= default]
程序员灯塔
转载请注明原文链接:=delete,=default
喜欢 (0)