题解 | #友元类#

友元类

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;
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务