Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Whats the difference between “public:”, “private:”, and “protected:”?

0
Posted

Whats the difference between “public:”, “private:”, and “protected:”?

0

* A member (either data member or member function) declared in a private: section of a class can only be accessed by member functions and friends[14] of that class * A member (either data member or member function) declared in a protected: section of a class can only be accessed by member functions and friends[14] of that class, and by member functions and friends[14] of derived classes * A member (either data member or member function) declared in a public: section of a class can be accessed by anyone ================================================== ============================

0

“Private:” is discussed in the previous section, and “public:” means “anyone can access it.” The third option, “protected:”, makes a member (either data member or member fn) accessible to subclasses.

0

• A member (either data member or member function) declared in a private section of a class can only be accessed by member functions and friends of that class • A member (either data member or member function) declared in a protected section of a class can only be accessed by member functions and friends of that class, and by member functions and friends of derived classes • A member (either data member or member function) declared in a public section of a class can be accessed by anyone [ Top | Bottom | Previous section | Next section | Search the FAQ ]

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123