"encompassing" areas for friendship classes

Bjarne Straustrup writes:

"a friend's class must be previously declared in the scope or defined in a nonclass area immediately including the class declaring it to be a friend

Is the first part of the statement redundant because “the non-classical area that directly includes the class” includes “previously declared in the scope”? IE: What is the difference in these two areas?

+3
source share
3 answers

I think in the first part the friend's class is declared inside the class (nested), which declares it to be a friend. While in the second part, the friend class is declared outside, immediately in front of the class that declared it a friend.

+1
source

Is it possible that the second part says "insert immediately", and the first does not? Therefore, I understand that if a class is declared in a non-classical scope (for example, in a namespace or global), it can only be immediately covering the scope (one at the top). If it is declared in a covered class (I think, nested classes), it can be as high as possible.

The value matters:

class Grandpa
{
    class Mother
    {
        class Junior
        {
            friend class Grandpa;
        };

    };
};

Just because there Grandpaare a few "class areas" above Junior.

+1
source

.

-1

Source: https://habr.com/ru/post/1726027/


All Articles