0
我有2類:預算和AuxiliaryOffice,我使用的朋友功能:朋友AuxiliaryOffice :: addBudget(double,Budget &);訪問預算的私人會員corpDivision。類的朋友
auxil.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
budget.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
auxil.cpp
#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 - >預算:: corpDivision是不可訪問
您有問題嗎? –
你的示例有幾個問題,特別是'corpBudget'沒有聲明,你的朋友聲明沒有返回類型。請在此工作。 –
請參閱http://sscce.org瞭解如何製作演示您的問題的示例程序。 –