Skip to content

Access Modifiers

Blokyk edited this page Jul 5, 2021 · 1 revision

What each access modifier means on each kind of declaration


Non-types

Namespace

Default : public

Allowed :

  • public :

    • namespace : ILLEGAL

    • global : Visible to every file that import the project

  • internal :

    • namespace : ILLEGAL

    • global : Only visible to files within the project

Function

Note : These are only valid for methods or namespaced functions, and not global functions. Putting an access modifier on a global function a) doesn't mean anything, and b) is illegal.

Default : private

Allowed :

  • public -- Visible to every file

  • internal -- Only visible to files within the project

  • protected -- Visible to all derived types of the containing class

  • protected internal -- Visible to all derived types of the containing class, given that the types are within the project

  • private -- Only visible to the containing type

Types

Note : By default, this assumes that

  1. Every type is declared within a namespace, and

  2. The other files use/import or are within said namespace

When this is not the case, the behavior will be listed as namespace, i.e. the type is declared within a namespace and global, i.e. the type is declared outside of a namespace

Class, struct, implementation

Default : public

Allowed :

  • public -- Visible to every file

  • internal -- Only visible to files within the project

  • protected -- Visible to all derived types of the containing class

    • Valid only for nested types
  • protected internal -- Visible to all derived types of the containing class, given that the types are within the project

    • Valid only for nested types
  • private -- Only visible to the containing class

    • Valid only for nested types

Interface, enum, trait

Default : public

Allowed :

  • public -- Visible to every file

  • internal -- Only visible to files within the project