I have created an overloaded operator for ++ in my .hpp file and then a function which calls it also in the .hpp file. The .cpp file then calls the function but when the function hit the ++ code it doesnt eneter the overloaded operator but instead used the default operation operator for ++. Why isnt it using my overloaded operator?
Here is the operators for ++:
iterator& operator ++ () { // pre-increment
std::list<value_type>::iterator i = listOfValues.begin();
advance(i,1);
return &*i;
}
Square_List operator ++ (int) { // post-increment
std::list<value_type>::iterator i = listOfValues.begin();
advance(i,1);
return &*i;
}
And here is the function using it:
template <typename A_>
void testerIncrement(A_ toInc)
{
toInc = listOfValues.begin();
cout << "\n" << *toInc;
++toInc;
cout << "\n" << *toInc;
++toInc;
}
And lastly the call for the function in the .cpp file
ca.testerIncrement(ca.listOfValues.begin());
You overload the prefix increment operator ++ with either a nonmember function operator that has one argument of class type or a reference to class type, or with a member function operator that has no arguments.
It seems you are using non member operators. So your syntax should be void operator++(iterator &); //prefix and void operator++(Square_List, int); //postfix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With