lundi 7 janvier 2019

Why can't my friend function access the private members?

The addBudget function in AuxiliaryOffice class is a friend function of the budget class. But the compiler is giving me error, that it cannot access the private members of the Budget class.

class Budget;
class AuxiliaryOffice
{
private:
    double auxBudget;
public:
    AuxiliaryOffice()
    {
        auxBudget = 0;
    }
    double getDivisionBudget()
    {
        return auxBudget;
    }
    void addBudget(double a, Budget &ref)
    {
        ref.corpBudget += a;
        auxBudget += a;
    }
};
class Budget
{
private:
    static double corpBudget;
    double divisionBudget;
    friend void AuxiliaryOffice::addBudget(double, Budget&);
public:
    Budget()
    {
        divisionBudget = 0;
    }
    void addBudget(double a)
    {
        corpBudget += a;
        divisionBudget += a;
    }
    double getDivisionBudget() const
    {
        return divisionBudget;
    }
    double getCorpBudget() const
    {
        return corpBudget;
    }
};
double Budget::corpBudget = 0;

Aucun commentaire:

Enregistrer un commentaire