【C++】课后习题p121 第8题

#include<iostream>
using namespace std;

class Student{
public:
    Student(int n, float s):num(n), score(s){}
    void  change(int n, float s){
        num = n;
        score = s;
    }
    void  display(){
        cout << " " << num << " " << score << endl;
    }
    friend void fun(Student &);
private:
   mutable  int num;
   mutable  float score;
};

void fun(Student &s){
    s.display();
    s.change(101, 80.5);
    s.display();

}
int main(){
    Student s1(10,78.5);
    fun(s1);
    
    return 1;
}

知识点是友元函数

猜你喜欢

转载自blog.csdn.net/weixin_40293999/article/details/132541385
今日推荐