我有 2 个类:Budget 和 AuxiliaryOffice,我正在使用一个朋友功能:friend AuxiliaryOffice::addBudget(double,Budget &); 访问 Budget 的私人成员 corpDivision。
辅助.h
#ifndef AUXIL_H
#define AUXIL_H
class Budget;
class AuxiliaryOffice
{
private:
double auxBudget;
public:
AuxiliaryOffice(){auxBudget=0.0;}
double getDivisionBudget()const{return auxBudget;}
void addBudget(double b, Budget &);
};
#endif
预算.h
#include"auxil.h"
#ifndef BUDGET_H
#define BUDGET_H
class Budget
{
private:
static double corpDivision;
double divisionBudget;
public:
Budget(){divisionBudget=0.0;}
void addBudget(double b){divisionBudget+=b; corpBudget+=b;}
double getDivisionBudget()const{return divisioBudget;}
double getCorpDivision()const{return corpDivision;}
friend AuxiliaryOffice::addBudget(double,Budget &);
};
#endif
辅助文件
#include"auxil.h"
#include"budget.h"
void AuxiliaryOffice::addBudget(double b, Budget& div)
{
auxBudget+=b;
**div.corpDivision+=b;** //this line it is the problem.
}
div.corpDivision+=b -> Budget::corpDivision 不可访问