Home > Backend Development > C#.Net Tutorial > Summary of C++ review key points: Five static member variables and member functions

Summary of C++ review key points: Five static member variables and member functions

黄舟
Release: 2017-01-16 11:27:14
Original
1438 people have browsed it

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

1. Static member variables

1) Define static member variables

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

static members Provides a sharing mechanism for similar objects

Ø When a member of a class is specified as static, no matter how many objects of this class are created, these objects share this static member

Ø Static members Belongs to a class, it is not an object member

Summary of C++ review key points: Five static member variables and member functions

2. Static member function

1) Concept

Ø The number of static member functions is preceded by key Word static

Ø Static member function provides common operations that do not depend on the class data structure. It does not have this pointer

Ø When calling a static member function outside the class, use "class name::" as a qualification word, or calling through an object

Summary of C++ review key points: Five static member variables and member functions

# Difficult question: Ordinary variables cannot be used in static member functions.

//Static member variables belong to the entire class. It is not clear whether they are attributes of that specific object.

Summary of C++ review key points: Five static member variables and member functions

Summary: static modified member variables belong to the class itself, ordinary member variables belong to objects, and there will be as many corresponding member variables as there are objects; static members Variables are shared.

The function modified by static belongs to the class itself, and static functions cannot access non-static variables! Static functions can be accessed through objects or through class names.

The above is the content of static member variables and member functions in the fifth summary of C++ review points. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template