Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How C++ members dereferencing operators

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about how C++ members unquote operators. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Taking a look at the member dereferencing operator, C++ allows you to define pointers to class members, and you need to use a special representation when declaring or dereferencing such pointers.

Example:

Class Example {private: int feet; int inches;public: Example (); Example (int ft); ~ Example (); void show_in () const; void show_ft () const; void use_ptr () const;}

If there is no specific object, the inches member is just a label. That is, the class defines inches as a member identifier, but allocates memory for it. An object of this class must be declared:

Example ob;// now exists in ob.inches

Therefore, the identifier inches can be used in conjunction with a specific object to refer to the actual memory unit (for member functions, the object name can be omitted, but the object is considered a pointer execution object).

C++ allows you to define a member pointer to the identifier inches:

Int Example::*pt = & Example::inchers

This kind of pointer is different from the regular pointer. The regular pointer points to a specific cell, while the pt pointer does not point to a specific memory cell, because the declaration does not indicate a specific object. The pointer pt refers to the position of the inches member in any Example object. Like the identifier inches, pt is designed to be used with object identifiers. Actually. The expression * pt makes assumptions about the role of the identifier inches, so you can use an object identifier to specify the object to access and a pt pointer to specify the inches members of that object. For example, a class method can use the following code:

Int Example::*pt = & Example::inches;Example ob1;Example ob2;Example * pq = new Example;cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report