I have a question that I can't seem to find an answer for, and I am wondering if someone here might be able to lend me some knowledge.
I am curious as to how the computer knows which member function to call, post or pre-increment, when operator notation is used in the main program. I can understand how it would be know using function notation, such as the following:
obj1.operator++(); // Pre-increment call
obj1.operator++(0); // Post-increment call
But how does it know which one to call if this was the code:
++obj1; // Pre-increment call
obj1++; // Post-increment call
Please reference the following test code:
Code:
class Test
{
public:
Test(signed short int = 0);
void operator++();
void operator++(int);
private:
signed short int var;
};
Test::Test(signed short int tvar)
{
var = tvar;
}
void Test::operator++()
{
++var;
}
void Test::operator++(int x)
{
var++;
}
signed int main()
{
Test obj(1);
++obj;
obj++;
obj.operator++();
obj.operator++(0);
}
Thanks,
Jaymes76
Edit: Fixed object name mismatch - didn't change the point of the post, however - just nitpicky on my part.