=delete,=default
- [= 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]