题解 | #友元类#
友元类
https://www.nowcoder.com/practice/ef9d1e6d37764523a33037b8879dd7cc
#include<bits/stdc++.h> using namespace std; class phone{ // write your code here...... friend class myphone; private: int price; public: phone(int x){ price=x; } }; class myphone{ private: phone a; public: myphone(int x):a(x){ } int getprice(){ return a.price; } }; int main(){ int p; cin>>p; myphone a(p); cout<<a.getprice(); return 0; }