Tuesday, 15 March 2011

c++ - Friend declaration for single member instead of whole class? -



c++ - Friend declaration for single member instead of whole class? -

normally in c++ when class declares friendship class b, class b has total access class private members. need allow class b access 1 private fellow member of class , nil else. there way it, maybe new in c++11?

not i'm aware of. if it's of import allow access single member, wrap info in class (c) has exclusively private members, create class friend of b , provide public accessor c object in a.

something this:

template<class t> class mateswithb { friend class b; public: mateswithb( t & val ) : data(val) {} private: t& data; operator t&() { homecoming data; } operator const t&() const { homecoming data; } }; class { // ... mateswithb<int> getprivatethingy() { homecoming mateswithb(thingy); } private: int thingy; // shared class b };

something that. haven't run through compiler check.

but wonder... when find needing this, isn't in design fundamentally flawed?

c++ oop class c++11 friend

No comments:

Post a Comment