I am trying to overload the operator<<
from the class second
. The problem is some of the data I am trying to access is private in class first
. Why am I unable to access the private data since I am using the friend function?
I found that the overload is only working with non-inherited private data.
class first
{
public:
student(string a, string b, float c, int d);
private:
string a;
string b;
float c;
int d;
int e;
static int count;
};
class second : public first
{
public:
second(string a, string b, float c, int d, string f);
friend ostream &operator << (ostream &output, second &dS);
friend istream &operator >> (istream &input, second &dS);
private:
string f;
};
// Separate File
ostream &operator <<(ostream& output, second& dS){
output << iS.a << endl;
output << iS.f << endl;
return output;
}
This is the error I am getting:
overload.cpp:27:18: error: 'a' is a private member of 'first'
output << dS.a << endl;
^
./example.hpp:51:9: note: declared private here
string a;