Initialization of static container objects in a class

Source: Internet
Author: User

A netizen asked:

"

In a class, there is a member variable static set <int> set. How to use a 1000 element to initialize it?

"

 

The initialization of special member variables in a class is very skillful. I wrote a blog post on this issue:

Initialization of member variables of Special Data Types

However, this blog does not include the question raised by the above user. The following code is provided:

# Include <set> # include <iostream> using namespace STD; Class test {PRIVATE: static set <int> set; public: static void print () {for (set <int >:: iterator iter = set. begin (); iter! = Set. end (); ++ ITER) {cout <* ITER <Endl ;}}; set <int> Init () {set <int> TMP; for (INT I = 0; I <1000; ++ I) {TMP. insert (I) ;}return TMP ;}set <int> test: Set (Init ()); // note that set <int> int main (INT argc, char ** argv) {test: Print (); Return 0;} must be included first ;}

From: http://blog.csdn.net/pathuang68/article/details/7745657

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.