Protected Members and Operator overloading

Hello. I have the following problem.

Simple example




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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?


Thanks in advance.
Last edited on
replace A const c with A const & c (or const A& c)

demo: http://ideone.com/TTDhz
Thanks a lot! And thanks for the quick reply.
Topic archived. No new replies allowed.