C + + Fourth day Note January 29, 2016 (Friday) a.m.

Source: Internet
Author: User
Tags class definition

1. Static members of a classstatic local variables:(1) The space of static local variables is not in the stack area. (2) Static local variables can retain the results of the last function call, similar to global variables, but static local variables can only be visible within the current function body. (3) If the static local variable is not initialized, it is initialized to 0 by the compiler. the declaration of a static variable is executed only once to ensure that the static variable has only one spaceinitialization of static member variables is initialized independently of the class definition,
Basic format: Type class Name:: Static member variable nameexample: int employee::next_id = 0;//The initialization of a static member variable, without specifying an initial value, the default is 0.
A static member variable has only one copy of space in memory and does not attach to an object's existence. Stored in: Global data area (static data area)non-static members in a class cannot be accessed in a static member function. Cause: The This pointer does not exist in a static member function. How static member functions are called:
(1): Class Name:: Function name (parameter list); Recommended Use
(2): Object name. function name (parameter list);2. Friend and friend function functions are divided into: global function, class member function, friend function of class friend: can access the private member of a class, but destroys the encapsulation of class. The friend function of the class and the global function are called in the same form.
3. Nested classes:declares the basic format of an inner class object: External class Name:: Internal class name Object name;

C + + Fourth day Note January 29, 2016 (Friday) a.m.

Related Article

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.