setX()

Hello!
Is there a mistake that we have to use constructor insetad of setX() method?

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  #include<iostream>
#include<cstdlib>

using namespace std;

class point {
  private:
   int x, y;
  public: 
   point(int x1, int y1);
   int getX();
   int getY();
   void print();
   point (const point & pt)
  { x = pt.x; y = pt.y; }

};

 point::point(int x1, int y1) {
  x = x1; 
  y = y1;
}

int point::getX() {
  return x; 
}

int point::getY() {
  return y; }
  void point::print() {
  cout << "(" << x << ", " << y << ") " << endl;
}



int main(){
  
  point a(3, 2);
  point b(1,1);
  a.getX();
  cout<<a.getX()<<endl;
  b.print();

  point d(a);
  cout<<"copy: "<<d<<endl; 

  return 0;
}


Many thanks!
Isn't this the same as this thread?
http://www.cplusplus.com/forum/beginner/126749/
O , hello!
No, not quite the same!
I wanted setX() method to CHANGE x I have still initiated.

I was told it should be possible. ...(problem is I am not sure what they ment at all!)
MANY THANKS , PEOPLE!!!
Last edited on
How about you add the prototype for the setX function between lines 12 and 13, for starters? It will have a return type of void and will take one parameter of type int.
Topic archived. No new replies allowed.