#include "student.h" // 引入student.h头文件,包含Student类的定义

using namespace std; // 使用std命名空间

void Student::setSid(const std::string &sid) // 定义Student类的成员函数setSid,设置学生的学号 { m_sid = sid; // 将传入的sid赋值给成员变量m_sid }

std::string Student::sid() const // 定义Student类的成员函数sid,返回学生的学号 { return m_sid; // 返回成员变量m_sid }

void Student::showInfo() // 定义Student类的成员函数showInfo,显示学生的信息 { cout << "sid " << m_sid << " name " << m_name << endl; // 输出学生的学号和姓名 }

std::ostream &operator<<(std::ostream &out, const Student &stu) // 重载输出流运算符<<,使得可以直接输出Student对象 { out << "sid " << stu.m_sid << " name " << stu.m_name; // 将学生的学号和姓名输出到out流中 return out; // 返回out流

#include studenthusing namespace std;void StudentsetSidconst stdstring &sid	m_sid = sid;stdstring Studentsid const	return m_sid;void StudentshowInfo 	cout sid m_sid name m_name endl; stdostre

原文地址: https://www.cveoy.top/t/topic/iSTZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录