当前位置:网站首页>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;
}
边栏推荐
- Function pointer, function pointer array, calculator + transfer table, etc
- Wandering -- the last programming challenge
- The Stones Game【取石子博弈 & 思维】
- Image of the basic component of the shutter
- 单片机集成开发环境Keil5的使用
- 两个栈的模拟题
- 时变和非时变
- 2019.11.13 training summary
- 2021年团体程序设计天梯赛-模拟赛
- Text of the basic component of the shutter
猜你喜欢
随机推荐
在VMware workstation中安装WMware ESXi 6.5.0并进行配置
2021年团体程序设计天梯赛-模拟赛
September 21, 2020 referer string segmentation boost gateway code organization level
Setinterval, setTimeout and requestanimationframe
Binding mechanism of JVM methods
Maze walking BFS medium + -- the last programming challenge
2019.10.16 training summary
Reverse thinking - short story
sympy的dsolve函数
manacher
PGP在加密技术中的应用
Download control 1 of custom control (downloadview1)
JVM instructions for four call methods
acwing271【杨老师的照相排列】【线性DP】
Ce projet Open source est super wow, des photos manuscrites sont générées en ligne
Beautiful ruins around Kiev -- a safe guide to Chernobyl!
L2-031 深入虎穴 (25 分)
Codeforces Round #645 (Div. 2)
Analyze in detail the PBOT mining virus family behavior and the principle of exploited vulnerabilities, and provide detailed protection suggestions for the blue army
2021 team programming ladder competition - Simulation Competition









