#include <iostream> #include <string> using namespace std; class Student { public: Student() {} Student( const string& nm, int sc = 0 ): name(nm), score(sc){} //(1)下面的const干神马?_____________ void set_student( const string& nm, int sc = 0 ) { name = nm; score = sc; } //(2)下面的const分别干神马?___________ const string& get_name() const { return name; } int get_score() const { return score; } private: string name; int score; }; //(3)下面的const干神马?_____________ void output_student(const Student& student ) { cout << student.get_name() << "\t"; cout << student.get_score() << endl; } int main() { Student stu( "Wang", 85 ); output_student( stu ); return 0; }
运行结果:
时间: 2024-10-09 06:29:23