G
Gary Wessle
Hi
I am trying to call a function of a class which declares an object of
another class and return its private member.
thanks
****************************************************************
int main(){
strategy1 m;
cout << m.get_balance() << endl;
}
****************
class strategy1 //interface
{
public:
double get_balance();
strategy1();
};
****************//implementation
strategy1::strategy1(){
cout << "strategy1 called" << endl;
}
double strategy1::get_balance(){
Account a;
return a.balance;
}
****************
class Account //interface
{
class strategy1;
friend class strategy1;
double balance; //<<--error line no. 12
public:
....
};
the error I am getting is
**************** error ****************
Account.h:12: error: 'double Account::balance' is private
I am trying to call a function of a class which declares an object of
another class and return its private member.
thanks
****************************************************************
int main(){
strategy1 m;
cout << m.get_balance() << endl;
}
****************
class strategy1 //interface
{
public:
double get_balance();
strategy1();
};
****************//implementation
strategy1::strategy1(){
cout << "strategy1 called" << endl;
}
double strategy1::get_balance(){
Account a;
return a.balance;
}
****************
class Account //interface
{
class strategy1;
friend class strategy1;
double balance; //<<--error line no. 12
public:
....
};
the error I am getting is
**************** error ****************
Account.h:12: error: 'double Account::balance' is private