Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of single case lazy and multithreaded by C++

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how C++ solves single-case lazy and multithreaded problems". The content is simple and clear. I hope it can help you solve your doubts. Now let the editor lead you to study and learn this article "how C++ solves single-case lazy and multithreaded problems".

Single-case lazy and multithreaded problems

As a singleton mode, only one memory space is created during the entire program run, in order to achieve this goal.

1. You need to set the constructor as a private member

2. You need a private static pointer to point to yourself

3. You need a public static function to expose the static pointer above.

The following code is an example of a slacker.

Click (here) to collapse or open

# include

Using namespace std

Class single_ins

{

Private:

Int a

Int b

Single_ins ()

{

A = 0

B = 0

}

Static single_ins* myc

Public:

Void setval (const int& a minute Const int& b)

{

This- > a = a

This- > b = b

}

Void print ()

{

Cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report