Why is my deep copy not working?

Why is my deep copy not working? Can anybody help me fix it ? I get the error "error: cannot convert ‘DeepCopy::getX’ from type ‘int (DeepCopy::)() const’ to type ‘int’"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  #include<iostream>

using namespace std;

class DeepCopy
{
public:
DeepCopy(int m) {x = new int; *x = m;}
DeepCopy(const DeepCopy& obj){x=new int; *x=obj.getX;}
~DeepCopy() {delete x;}
int getX() const {return *x;}
void setX (int m) {*x = m;}
void printX(){cout << "The value of X is " << *x << endl;}
private:
int *x;
};

int main()
{
DeepCopy obj1(10);
DeepCopy obj2 = obj1;
obj1.printX();
obj2.printX();

obj1.setX(12);
obj2.printX();
obj2.printX();

return 0;

}
Your code isn't calling the function.

*x=obj.getX should read *x=obj.getX().
Thanks.
Topic archived. No new replies allowed.