阅读背景:

C++之友元函数与友元类使用

来源:互联网 

1.友元类

#include <iostream>
using namespace std;

class Date {
public:
	Date(int year) {
		this->year = year;
	}
	friend class Test; //声明外界可以访问Data.year的友元类Test

private:
	int year;
};

class Test {
public:
	static void show() {
		Date birthday(2022);
		cout <<"before: " << birthday.year << endl;
		birthday.year = 2000;
		cout <<"after: "<< birthday.year << endl;
	}
};

int main(){
  Test::show();
	return 0;
}
#include <iostream>
using namespace



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: