I am struggling to find my way out of this situation. I just want to call the [] operator within the () operator, which will be finally used/written on the screen with the ostream << operator. Whenever I'm using the sintax _elements[index] the execution crashes with the error vector out of range.
Do you have any ideea what should be the correct code ?
Header File:
typedef unsigned int Uint;
typedef vector<Uint> TVint;
typedef vector<Uint>::const_iterator Titerator;
Well the problem is that according to my project index parameter is calculated and validated within the CalculateValues(index) method and furthermore I have to call the [] operator from the () operator.
Whenever I am using the sintax _elemente[index] within the () operator, the execution fails ( not the debugging ) with the error : vector subscript out of range.
It is working if the code is duplicated as follows:
Uint Sir:: operator [] (int index)
{
if (index <0)
{
throw outofrange();
}
_count=index+1;
CalculateValues(index);
return _elements[_count];
}
Sir& Sir::operator() (int index)
{
_count=index+1;
CalculateValues(index); [output] has to call the [] operator [/output]
return *this;
}
However it is mandatory that within the function () operator , the [] operator has to be called. But I can't figure out how shoudl that be performed, it's really a headache after all the sintax, this little bug is keeping me from the final call.