It seems to me there is no need to utilize a pointer to store
age
as shown below If you wish to utilize a pointer you should delete it before copying to it in the copy constructor else you will have memory leakage As to your question if I understand it You seem to be inquiring the location of the
*age
value It is of course stored at the memory address whose value is
age
#include <iostream>
#include <string>
using namespace std;
class Move
{
private:
int age;
public:
Move(int d);
Move(const Move& source);
~Move();
int get_value() { return age; }
};
Move::Move(int d)
{
age = d;
}
Move::Move(const Move& source)
{
age = source.age;
}
Move::~Move()
{
}
void display_element(Move P)
{
cout << "the age of p is: " << P.get_value()<<endl;
}
int main()
{
Move waleed(5);
display_element(waleed);
Move ahmed(waleed);
display_element(ahmed);
return 0;
}