Search code examples
c++access-specifier

C++ access specifiers, too few?


As far as i know, there're only 3 access-specifiers in C++: private, public, protected

With these 3 access-specifiers, how can i make a method usable to the classes in the project but unusable to the "foreigners" ??(like internal and public in C#)


Solution

  • C++ does not know what a project is.

    C++ knows about classes, where it offers the three access specifiers you mentioned.

    C++ knows about translation units, where it offers two access specifiers: internal and external linkage.

    Edit: About internal and external linkage, this is related to whether a symbol will be seen outside of the translation unit (the object file). Any global static or const variable defined in the TU has internal linkage. Others have external linkage.