当前位置:网站首页>September 25, 2020 noncopyable of boost library for singleton mode
September 25, 2020 noncopyable of boost library for singleton mode
2022-06-29 10:20:00 【qqq2018】
from boost::noncopyable Class inheritance
reason :
For singleton singleton object . When a class does not explicitly declare a constructor 、 Destructor 、 copy constructor 、 When assigning a constructor , The compiler generates by default , But sometimes we don't want them to have the ability to be copied or assigned .
Class :8 individual
https://editor.csdn.net/md/?articleId=108996157
Internal implementation :
Private copy constructor and assignment constructor , Subclass objects cannot be copied and assigned to other objects
//C++98 Is declared private
class noncopyable{
protected:
noncopyable() {
}
~noncopyable() {
}
private:
noncopyable( const noncopyable& ){
};
const noncopyable& operator=( const noncopyable& ){
return *this};
};
//c++11 of use delete Indicates no use ,default Means no action is taken
class noncopyable{
protected:
noncopyable() = default;
~noncopyable() = defalult;
noncopyable(const noncopyable &) = delete;
noncopyable& operator=(const noncopyable& ) = delete;
};
give an example :
#include <boost/noncopyable.hpp>
using namespace boost;
class test:public boost::noncopyable {
};
int main() {
test a, c;
test b(c); // Error. copy constructor
a = c;// Error. The mutator
return 0;
}
边栏推荐
- Application of keil5 integrated development environment for single chip microcomputer
- Talk about threads and concurrency
- The stones game
- 山科 的C语言2018练习题(电信)
- Rikka with cake (segment tree + segment tree)
- 1147 heaps (30 points)
- Analysis of liferayportal jsonws deserialization vulnerability (cve-2020-7961)
- Image of the basic component of the shutter
- Wandering --- 最后的编程挑战
- Reverse thinking - short story
猜你喜欢
随机推荐
HDU 6778 Car (分组枚举-->状压 dp)
2019.11.3 learning summary
1098 insertion or heap sort (25 points)
Codeforces - 1151b thinking
JVM method return address
2019.10.27 training summary
Sixteen system counter and flow lamp
L2-025 分而治之 (25 分)
L2-025 divide and rule (25 points)
Download control 1 of custom control (downloadview1)
JVM instructions for four call methods
Codeforces Round #645 (Div. 2)
基辅周边的凄美废墟——切尔诺贝利的安全前往指南!
Codeforces Round #652 (Div. 2)
Recurrence of vulnerability analysis for Cisco ASA, FTD and hyperflex HX
Analysis of liferayportal jsonws deserialization vulnerability (cve-2020-7961)
Rikka with Cake(线段树+线段树)
Shanke's C language 2018 exercise (Telecom)
这个开源项目超哇塞,手写照片在线生成
2019.11.20训练总结









