I am currently writing code for a class where I need to overload the << and >> operators....now when I do so it gives me errors that the private components I'm trying to access within the class are unaccessable...
I have defined both the << and >> operator overloads as friends in the class description but still it says it cannot access the members
Is there something else I need to do? heres some snippets of code
Code:
class Store
{
friend ostream & operator>>(ostream&, const Store &);
friend istream & operator<<(istream&, Store &);
public:
.....
private:
float revenue;
int numOwners;
Owner *owners;
void copy(const Store &s);
void free();
};
istream &operator>>(istream &in, Store &c)
{
int i;
in >> ws >> c.name >> c.revenue >> c.numOwners;
c.owners=new Owner[c.numOwners+1];
for(i=0; i<c.numOwners; i++)
{
c.owners[i].read(inn);
}
return in;
}
ostream &operator<<(ostream &out, const Store &c)
{
int i;
out << "Name: " << c.name <<endl;
out << "Revenue: " <<setiosflags(ios::showpoint) << setiosflags(ios::fixed) << setprecision(2) << c.revenue << " (in Millons)" <<endl;
out << "NumOwners: " << c.numOwners <<endl;
out << "Owners:" <<endl;
for(i=0; i<c.numOwners; i++)
{
c.owners[i].print(out);
}
return out;
}
and with this I get errors for in accesability like:
"cxx: Error: Store.cc, line 121: member "Store::revenue" is inaccessible
in >> ws >> c.name >> c.revenue >> c.numOwners;
--------------------------------^
cxx: Error: Store.cc, line 121: member "Store::numOwners" is inaccessible
in >> ws >> c.name >> c.revenue >> c.numOwners;
---------------------------------------------^
cxx: Error: Store.cc, line 123: member "Store:wners" is inaccessible
c.owners=new Owner[c.numOwners+1];
----------^"
etc
Anything I am forgetting? I cant see it if i did
Thanks,
Arm