S
Srini nandiraju
Hi folks,
I am trying to implement a friend class and the following is what I did.
Please scroll down.
/***************** CODE **********************************/
class BKP
{
private:
int nVar;
vector<int> p;
vector<int> w;
int b;
public:
BKP();
BKP(ifstream &in);
~BKP();
friend ostream &operator<<( ostream &_os, BKP& _bkp);
};
ostream& operator <<( ostream& _os, BKP& _bkp)
{
for ( int i =0; i <_bkp.nVar ; i++)
{
_os << _bkp.p.at(i) << " " << _bkp.w.at(i) << endl;
}
_os << _bkp.b <<endl;
return _os;
}
I tried to compile in MSVC++ 6.0 and I get the following errors:
error C2248: 'nVar' : cannot access private member declared in class 'BKP'
error C2248: 'p' : cannot access private member declared in class 'BKP'
error C2248: 'w' : cannot access private member declared in class 'BKP'
error C2248: 'b': cannot access private member declared in class 'BKP'
I can't figure this. A friend function is supposed to access the private
members is what I read. Please clarify. thanx for ur time.
srini.
I am trying to implement a friend class and the following is what I did.
Please scroll down.
/***************** CODE **********************************/
class BKP
{
private:
int nVar;
vector<int> p;
vector<int> w;
int b;
public:
BKP();
BKP(ifstream &in);
~BKP();
friend ostream &operator<<( ostream &_os, BKP& _bkp);
};
ostream& operator <<( ostream& _os, BKP& _bkp)
{
for ( int i =0; i <_bkp.nVar ; i++)
{
_os << _bkp.p.at(i) << " " << _bkp.w.at(i) << endl;
}
_os << _bkp.b <<endl;
return _os;
}
I tried to compile in MSVC++ 6.0 and I get the following errors:
error C2248: 'nVar' : cannot access private member declared in class 'BKP'
error C2248: 'p' : cannot access private member declared in class 'BKP'
error C2248: 'w' : cannot access private member declared in class 'BKP'
error C2248: 'b': cannot access private member declared in class 'BKP'
I can't figure this. A friend function is supposed to access the private
members is what I read. Please clarify. thanx for ur time.
srini.