the code is running properly but I just wondering why calling function Show() by using pointer can return the value of x, y, z to the objectA, why not the address? Because the pointer stored the address. But how can it give value to the function Show()?
#include <iostream>
using namespace std;
class _3D {
double x, y, z;
public:
_3D();
_3D(double initX, double initY, double initZ);
void Show() {
cout << x << " " << y << " " << z << "\n";
}
};
// Overloaded constructor
_3D::_3D(double initX, double initY, double initZ) {
x = initX;
y = initY;
z = initZ;
cout << "With arguments!!!\n";
}
// Class _3D constructor without arguments
_3D::_3D() {
x = y = z = 0;
cout << "No arguments!!!\n";
}
void main() {
_3D A(3, 4, 0);
_3D B;
// Creating a pointer and adding with the A object's address to the object of _3D type
_3D*PA = &A;
// Calling the function Show()
PA->Show();
system("pause");
}