Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'enclosing' scopes for friendship classes

Tags:

c++

scope

Bjarne Stroustrup writes:

"a friend class must be previously declared in an enclosing scope or defined in the non-class scope immediately enclosing the class that is declaring it a friend"

Isn't the first part of the statement redundant, because the "non-class scope immediately enclosing the class " includes "previously declared in an enclosing scope"? IE:, what is the difference in these two scopes?

like image 262
Trent Avatar asked Dec 02 '25 05:12

Trent


1 Answers

I think in the first part, the friend class is declared inside a class (nested) that declares it a friend. While in the second part, the friend class is declared outside, just before the class that declared it a friend.

like image 126
jasonline Avatar answered Dec 04 '25 20:12

jasonline