64,654
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
class Student;
class Teacher{
//希望Teacher类访问Student类的成员
public:
void print(Student & a);
};
class Student{
private:
//把Teacher类声明为Student类的友元类
friend Teacher;
int age;
public:
Student(int age)
{
this->age = age;
}
};
void Teacher::print(Student & a){
cout << a.age << endl;
}
void main(){
Student a(10);
Teacher t;
t.print(a);
system("pause");
}
cout << "+"
吧