Hi!
I've got some problems with overloading >> operator.
I need to write a class which will satisfy such test code:
1 2 3 4 5 6 7 8
|
stack S1, S2;
(...)
int a,b,c,d;
S1 >> a >> b;
S2 >> c;
S2 >> d;
(...)
|
and then print values of a,b,c,d. The idea is to pop back from the stack (implemented in class stack) int value to variable which states after >>.
I have written such overload of >> operator:
1 2 3 4 5 6 7 8 9
|
int operator >> (int &sink)
{
if(content.empty())
{
sink = content.back();
content.pop_back();
}
return sink;
}
|
The stack is implemented as a vector of int-s, which is called 'content'.
And now: what is the problem? The program prints out correctly values of a,c and d. Problem occurs with b, that is after the second pass of right shift operator.
The compiler says:
warning: value computed is not used
warning: 'b' may be used uninitialized in this function
I think, that something is wrong with my overloaded operator>>. But I've no idea how should I correct it :(
Thanks for your replies!