a problem (with file organizing?)

Hi. I'm having some problems with my code. Please, could you correct it?


Ex21.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include "Point.h"

int main()
{

    Point piste1;
    piste1.setXY(1,3);
    
    Point piste2(12, 23);
    
    Point piste3(piste2);
    
    system("PAUSE");
    return 0;
}


Point.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Point
{
      public:
             Point();
             Point(int xx, int yy);
             //third constructor
             Point(const Point &c);
             ~Point();
             void setXY(int xx, int yy);
             void setX(int xx);
             void setY(int yy);
             int getX();
             int getY();
             void printPoint();
             
      private:
              int x;
              int y;
};


Point.cpp:
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
  #include <iostream>
#include "Point.h"

Point::Point(){}

Point::Point(int xx, int yy)
{
    x=xx;
    y=yx;                         
}

Point::Point(const Point &c){}

Point::~Point(){}

void Point::setXY(int xx, int yy)
{
     x=xx;
     y=yy;         
}

void Point::setX(int xx)
{
     x=xx;     
}

void Point::setY(int yy)
{
     x=yy;     
}

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

int Point::getY()
{
    return y;   
}

void Point::printPoint()
{
    cout << "(" << x << "," << y << ")" << endl;     
}
I see a typo here:
1
2
3
4
5
Point::Point(int xx, int yy)
{
    x=xx;
    y=yx;                         
}

Apart from that, what specifically do need help with?
What problems?
When I try compiling the code, I get a lot of linker errors.

[Linker error] undefined reference to `Point::Point()'
[Linker error] undefined reference to `Point::setXY(int, int)'
[Linker error] undefined reference to `Point::Point(int, int)'
[Linker error] undefined reference to `Point::Point(int, int)'
[Linker error] undefined reference to `Point::~Point()'
[Linker error] undefined reference to `Point::~Point()'

etc.
Well, probably your source file "point.cpp" is not in your workspace. Check and try again.
Last edited on
The compilation must first generate object file from each *.cpp file and then the linker has to access both object files (and necessary libraries) to produce the executable.

You have code for the methods, so the build rules probably do not include the Point.cpp (and/or corresponding object file). The fix depends on your build environment.
Topic archived. No new replies allowed.