Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) public

 

public is a keyword for setting class access level to public (the other access levels are private and protected) or for public inheritance.

 

The public part of a class is called its interface.

 

A class created with the keyword class has a private access level by default, a class created by the keyword struct has public access level by default.

 

 

 

 

 

Examples

 

 

 

 

 

 

Advice

 

 

 

 

 

References

 

  1. Herb Sutter. Exceptional C++. ISBN: 0-201-61562-2. Item 23, page 84, guideline: 'Avoid public virtual functions; prefer using the Template Method pattern instead'
  2. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 20.7. Advice. page 611: '[11] Prefer public members for interfaces'

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict