88. Static members of a class, and implementations of inheriting multithreaded classes

Source: Internet
Author: User

1#include <iostream>2#include <thread>3 using namespacestd;4 5 classMyClass6 {7  Public:8     //Static is initialized only once9     Static intnum;Ten MyClass () One     { Anum + =1; -     } -~MyClass () the     { -num-=1; -     } - }; + 21//Static members do not belong to any one object, any object can access 22//For homogeneous object communication at intMyclass::num =3; -  - classMythread: PublicThread - { -  Public: -     Static intcount; in  -  Public: to     //overloading two constructors +Mythread (): Thread ()//Subclass Call Parent class constructor -     { the  *     } $Template<typename t,typename ... Args>Panax NotoginsengMythread (T &&func, Args &&...args): Thread (Forward<t> (func), forward<args>(args) ...) -     { the  +     } A }; the  + intMythread::count =0; -  $ voidGo () $ { -      while(1) -     { theMythread::count + =1; -cout << this_thread::get_id () <<" "<< Mythread::count <<Endl;WuyiThis_thread::sleep_for (Chrono::seconds (3)); the     } -      Wu } -  About voidMain () $ { -     //MyClass my1, My2, my3; -     //cout << my1.num << Endl; -     //cout << my2.num << Endl; A     //cout << my3.num << Endl; +  the mythread my1 (go); - mythread my2 (go); $ mythread my3 (go); theCin.Get(); the}

88. Static members of a class, and implementations of inheriting multithreaded classes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.