Inside the A.h
class A {
public:
friend ostream& operator<<(ostream &out, A const c);
protected:
int i;
};
And in the .cpp file A.cpp
ostream& operator<< (ostream &output, const A &dataToPrint)
{
cout << dataToPrint.i << endl;
return output;
}
The error I am getting is
error C2248: 'A::i' : cannot access protected member declared in class 'A'
I know is because the i is protected and if I convert it to private it works. But how can I make it work without changing the protected?