小白Harvey 2021-10-23 14:01 采纳率: 100%
浏览 21
已结题

将student设为友元不是能直接访问吗

#include<iostream>
using namespace std;
class Variable
{
friend class Studentprivate:
        string name;
        double score;
};


class Student
{

    public:
        Student(string name,double score);
    static    double Getaverage();
    static    int Number();
    private: 
        static double total;
        static int count;
 };
         double Student::total=0.0f;
         int Student::count=0;
         
Student::Student(string name,double score)
    :name(name),score(score) 
 {
     count++;
     total+=score;
 }
 
 double Student::Getaverage()
{
    return total/count;
}

img

  • 写回答

1条回答 默认 最新

  • CSDN专家-link 2021-10-23 14:04
    关注

    27行属于乱写,student类根本就没有这两个属性,你赋什麽值啊

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月1日
  • 已采纳回答 10月24日
  • 创建了问题 10月23日