I have this class in a project for school:
Code:
class info
{
friend istream & operator >>(istream &, info&);
friend ostream & operator <<(ostream &, const info &);
public:
bool operator<( const info & ) const;
const info & operator=(const info & );
void setId(int);
bool operator==(const info &) const;
private:
char name[20];
int id;
int age;
};
Now for the << and >> operators, I have this:
Code:
istream & operator >>(istream & in, info& l)
{
in >> l.age >> l.id >> l.name;
return in;
}
ostream & operator <<(ostream & out, const info & l)
{
out << l.age <<' ' << l.id <<' ' << l.name;
return out;
}
VC++ gives me a compile error for both of those saying "error C2248: 'age' : cannot access private member declared in class 'info'." This error occurs for each of the 3 variables. It is my understanding that a friend is able to access all private members of the class. So, why am I getting this error? Thanks.
-Tristan