c++ - Is a local class in a method of a class a friend of this class? -
i have outer class a
. has method a::fun
. in method, has local or inner class b
. question is: b
friend of a
?
i think not. right? if so, think let class b
friend of a
beneficial since b
can access a
's private , protected members. , moreover, sinceb
local in methods, not accessible others , safe friend of a
. how work around let b
access a
's private , protected members?
no not friends.
but local classes have same access names outside function function itself.
the standard says :
9.8 local class declarations [class.local]
a class can declared within function definition; such class called local class. name of local class local enclosing scope. the local class in scope of enclosing scope, , has same access names outside function enclosing function. declarations in local class shall not odr-use (3.2) variable automatic storage duration enclosing scope.
the big difference take in count local class accessible inside function.
but after :
- a friend of class function or class given permission use private , protected member names class.
- the local class in scope of enclosing scope, , has same access names outside function enclosing function. is, can access protected , private members of class function belongs.
Comments
Post a Comment