class A { private: int key; // give class B access to class A friend class B; }; class B { // new object from class A A new_a; void fn(){ // access private value from class B new_a.key; } }