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 to use the C++ control keyword protected

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "how to use the C++ control keyword protected". In daily operation, I believe many people have doubts about how to use the C++ control keyword protected. The editor consulted all kinds of materials and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the doubts about "how to use the C++ control keyword protected". Next, please follow the editor to study!

The keyword protected is similar to private in that you can only use public class members to access protected members outside the class. Only when derived can the private and protected keywords reflect the difference. Members of the derived class can directly access the protected members of the base class, but not the private members of the base class. So for external classes, protected is similar to private, while for derived classes, protected is similar to public.

For example, the Human class sets the name member to protected:

Class Human {protected: string name;...}

In this case, its derived class Hero can access name directly without using the methods in Human:

Class Hero: public Human {void show () {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