当前位置:网站首页>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;
}
边栏推荐
- 同花顺炒股软件可靠吗,安全吗?
- To 3 -- the last programming challenge
- Power Strings【KMP循环节】
- 【51nod 1215】数组的宽度
- If I were in Beijing, where would it be better to open an account? In addition, is it safe to open an account online now?
- The stones game
- QGIS mapping
- Judgment of points inside and outside polygon
- Pipeline details of IPC (interprocess communication)
- 1146 Topological Order (25 分)
猜你喜欢

Codeforces Round #645 (Div. 2)

Using rancher to build kubernetes cluster

Simulation problem of two stacks

1146 Topological Order (25 分)

Container of the basic component of the flutter

Nacos环境隔离

Application of keil5 integrated development environment for single chip microcomputer

1146 topological order (25 points)

GridView of basic component of shutter

Beautiful ruins around Kiev -- a safe guide to Chernobyl!
随机推荐
The stones game
Codeforces Round #657 Div. 2
manacher
nacos注册中心集群
Codeforces Round #659 (Div. 2)
2019.11.3 learning summary
2019.10.20 training summary
Substring score - Ultra detailed version - the last programming challenge
EDA与VHDL题库
蛇形填数
2019.10.6 training summary
September 21, 2020 referer string segmentation boost gateway code organization level
点在多边形内外的判断
Image of the basic component of the shutter
L2-026 small generation (25 points)
2019.10.16 training summary
Language characteristics
山科 的C语言2018练习题(电信)
图片验证码控件
URAL1517 Freedom of Choice 【后缀数组:最长公共连续子串】