Review of C + + summary of five static member variables and member functions

Source: Internet
Author: User
Thinking: Each variable has properties. Are there some attributes that are owned by all objects?

1. Static member variables

1) defining static member variables

Ø keyword static can be used to describe a member of a class,

Static members provide a shared mechanism for a homogeneous object

Ø when a member of a class is described as static, this class, regardless of how many objects are created, share this static member

Ø static member belongs to class, it is not an object member

2. Static member functions

1) Concept

Ø static member function number is prefixed with the keyword static

The static member function provides a common operation that does not depend on the class data structure, and it does not have this pointer

Ø call a static member function outside the class with a "class name::" As a qualifier, or through an object call

Problematic: Static member functions cannot use normal variables.

A static member variable belongs to the entire class, which is not clear, and is the property of that specific object.

Summary: Static modified member variables belong to the class itself, ordinary member variables belong to the object, how many objects will have the corresponding member variables, static member variables are common.

Static functions that are part of the class itself are not allowed to access non-static variables! Static functions can be accessed through object access or through the class name.

The above is the C + + review points summary of the five static member variables and member functions of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.