C++ Friend Classes -
just trying make sure have understood friends one
class { friend class b; int valueone; int valuetwo; public: int getvalueone(){ return valueone; } } class b { public: friendlydata; int getvaluetwo(){ return friendlydata.valuetwo; } } main() { b myobject; myobject.friendlydata.getvalueone(); // ok? myobject.getvaluetwo(); // ok? }
in reference code about, if ignore lack of initialising, 2 functions in main ok right? , besides doing funky stuff, should no other way data these classes... out side of these class, b.a
has no accessible data, member function.
yes 2 identified calls in main
ok. involve access of 3 members: b::a
, b::getvaluetwo
, a::getvalueone
. of have public
accessibility , expose no privae types. hence they're usable anywhere including main
.
Comments
Post a Comment