#include "iostream"
using namespace std;
class A{
private:
int i;
int a;
int b;
public:
A(int a, int b)
{
this->a = a;
this->b = b;
}
public:
friend void FriendFun(A *fun, int x);
int getA()
{
return this->a;
}
};
void FriendFun(A *fun, int x)
{
fun->a = x;
}
void main()
{
int x;
A a(1, 2);
FriendFun(&a, 3);
cout << a.getA() << endl;
system("pause");
}
c++_友元函数
最新推荐文章于 2024-09-06 16:17:58 发布
本文介绍了一个使用C++实现的包含友元函数的类的示例。该示例展示了如何定义一个类,并在该类中声明一个友元函数以访问类的私有成员变量。通过主函数调用友元函数并修改类实例的私有成员变量,最后输出修改后的值。
253

被折叠的 条评论
为什么被折叠?



