When I executed the following code the output appears to be very strange to me. Can any one explain this unexpected result to me.
The code:
#include <iostream>
using namespace std;
class Y
{
private:
int x;
public:
Y()
{
x = 7;
}
int getX()
{
return x;
}
int setX( int s )
{
x = s;
return x;
}
};
void main()
{
Y myY;
cout<< ( myY.setX(12) ) << ' ' << ( myY.getX() ) << endl; //1
int m;
cout<< (m=10) << ' ' << (m=12) << ' ' << (m=14) << endl; //2
}
The first 'cout' prints:
12 7
But it should ouput:
12 12
The second 'cout' prints:
10 10 10
But it should output:
10 12 14
I'm using c++ dotNet 2005 student edition win 32 console application.
Please fully explain this behaviour to me.
Thanks in advance
WaelTheNoble