热门

最新

红包

立Flag

投票

同城

我的

发布
qq_54017663
TCC 30 S
5 年前
trueqq_54017663

C++里的类中顺序问题
#include <iostream>
#include <string>
using namespace std;

class Teacher2;
class Student2
{
private:
int num;
float score;
public:
Student2(int n, float s);
void display(Teacher2& t);
};
Student2::Student2(int n, float s)
{
num = n;
score = s;
}

class Teacher2
{
public:
friend void Student2::display(Teacher2& t);
Teacher2(string m);
private:
string num;

};
Teacher2::Teacher2(string m)
{
num = m;
}
void Student2::display(Teacher2& t)
{
cout << "学生num为:" << num << " " << "学生score为:" << score << endl;
cout << "老师num为:" << t.num << endl;
}
int main()
{
Student2 s1(1001, 90.5), s2(1002, 80), s3(1003, 70.5);
Teacher2 t1("20010761"), t2("20024322"), t3("20035673");
s1.display(t1);
s2.display(t2);
s3.display(t3);
return 0;
}
注意display的位置

CSDN App 扫码分享
分享
评论
1
打赏
  • 复制链接
  • 举报
下一条:
如何将click存储的参数放到立即申报这个里边啊
立即登录