SocReg is a class I've defined:
1 2 3 4 5 6 7
|
class SocReg
{
long resetValue;
long qCurrent;
long qNext;
public:
// etc.
|
I was trying to model your example, but I guess I didn't understand it. So, is the correct syntax to identify the element in SocReg that should receive the input, as the second parameter in the overload?
EDIT:
I think I have little better understanding of this now. I've made the following change:
1 2
|
// s >> my_int (a.at(i));
s >> a.at(i);
|
And modified the parameters for the overload as follows:
1 2
|
//istream& operator >> ( istream& ins, const my_int& n )
istream& operator >> ( istream& ins, SocReg& n )
|
Now, the problem I'm having is how to actually assign the input value into the object. This produces a runtime error (invalid memory):
if (ins >> n)
And this doesn't compile, because the object member is of course private:
if (ins >> n.qNext)
I do have a set() function, but I don't know how to form the code to make this work with the >> operator.
Am I at least in the ballpark here?
EDIT #2:
I cheated and did this:
1 2 3 4 5 6 7 8 9 10 11 12
|
long tempLong;
// only continue if all OK
while (ins && !ins.eof())
{
// get an integer -- if OK then we're done
if (ins >> tempLong)
{
n = tempLong;
break;
}
|
It seems to work, but I'd be interested in knowing the "correct" way of doing this for future reference. Thanks for bearing with me.