0

Why does following does not work ??

```
#include<iostream>
using namespace std;
class point{
float x,y,z;
public:
point(float f_x =1.0, float f_y=1.0, float f_z=1.0);
void getxyz(float &x, float &y, float &z);
};
point::point(float f_x, float f_y, float f_z)
{
x= f_x;
y= f_y;
z= f_z;
}
void point::getxyz(float &x, float &y, float &z)
{
x=x+2;
y=y+2;
z=z+2;
}
int main()
{
float X,Y,Z;
point mylocation(8,3,4);
mylocation.getxyz(X,Y,Z);
cout<< X << " " << Y << " " << Z << endl;
return 0;
}
```

Output should be 10, 5 ,6

But this program works fine.......

```
#include<iostream>
using namespace std;
class point{
float x,y,z;
public:
point(float f_x =1.0, float f_y=1.0, float f_z=1.0);
void getxyz(float &x, float &y, float &z);
float getX();
float getY();
float getZ();
};
point::point(float f_x, float f_y, float f_z)
{
x= f_x;
y= f_y;
z= f_z;
}
float point::getX()
{
return x;
}
float point::getY()
{
return y;
}
float point::getZ()
{
return z;
}
void point::getxyz(float &x, float &y, float &z)
{
x=getX()+2;
y=getY()+2;
z=getZ()+2;
}
int main()
{
float X,Y,Z;
point mylocation(8,3,4);
mylocation.getxyz(X,Y,Z);
cout<< X << " " << Y << " " << Z << endl;
return 0;
}
```

Why is so?? (In previous program) After all x can be accessed by the members of same class and getxyz function belongs to same class.