#include <iostream.h>标签:友元,函数,int,C++,Student,operator,include,cout From: https://blog.51cto.com/u_15990596/6101649
#include <string>
class Student
{
private:
int age;
public:
Student(){
age=10;
}
out()
{
cout<<age<<endl;
}
//申明友元函数
必须要在类中申明 但是不是类成员函数
friend operator+(int i,Student &t);
};
//函数定义 不用类符号
operator+(int i,Student &t)
{
cout<<i+t.age<<endl;
}
int main()
{
Student t;
4+t;
return 0;
}