现在的位置: 首页 > 综合 > 正文

c++中友元函数访问私有变量及函数

2013年09月19日 ⁄ 综合 ⁄ 共 176字 ⁄ 字号 评论关闭
#include<iostream>

using namespace std;

class A{
private:
	
	int i;
	void fun1()
	{
		i = 40;
		cout<<"output something like this"<<endl;
	}

	friend int main();
	
};


int main()
{
	A a;
	a.fun1();
	cout<<a.i<<endl;

	return 0;
}

抱歉!评论已关闭.