C++ equivalent of C#'s internal

.net, c#, c++, visual-c++

Solution

There is no direct equivalent of `internal` in C++. Apart from `public`/`protected`/`private` the only other access control mechanism is `friend`, a mechanism by which can allow specific classes access to all members of your own class.

It could therefore be used as an `internal`-like access control mechanism, with the big difference being that:

- you have to explicitly declare `friend` classes one by one

- `friend` classes have access to all members without exception; this is an extremely high level of access and can introduce tight coupling (which is the reason why the customary reflex reaction to `friend` is "do you really need that?")

See also When should you use 'friend' in C++?

Problem

I am trying to backport some code from C# to C++ to get around an annoying problem, and what like to ask if anyone knows what the equivalent of C#'s 'internal' would be in C++. Here's an example of the it in use: ``` internal int InternalArray__ICollection_get_Count () { return Length; } ```

Original source

Related problems