Hello everybody.
I would like to test the short int variable wrapping. In the main() function it works, but when i wrote another function which increment a variable and should return overloaded i mean (wrapped) short number. But it return the same limited number as i initialized.
Code ex:
----------------------------------------------------
/* short int overload */
#include <iostream>
unsigned short int ovLod(unsigned short int plius)
{
std::cout << "Took "<< plius << std::endl;
return(plius++);
}
int main()
{
unsigned short int imPeln = 65534;
Because plius is only in function scope and your returning it to nothing. You function needs to either pass the parameter in by reference or have your function call assign the return value to imPeln: imPeln = ovLod( imPeln );
Also, not sure at what point you are expecting it to roll over to 0, but an unsigned short has a range of 0 to 65535, so it's not going to roll over until you increment it twice.
On top of that, you're using the post-increment operator inside ovLod, which takes the old value of plius and increments it after that. So the old value is returned and the new one is lost.