unresolved external symbol

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
class Character{

public:

    int getXCoord();
    void setXCoord(int xCoord);

    int getYCoord();
    void setYCoord(int yCoord);

    int itsXCoord;
    int itsYCoord;

};
void Move(){
int move;
Character Hero;
Hero.setXCoord(0);
Hero.setYCoord(0);
cout << "You are at :" << Hero.getXCoord() << ", " << Hero.getYCoord() << endl;
cout << "1)North 2)South 3)East 4)West: ";
cin >> move;
if (move == 1){
    Hero.itsXCoord += 1;
}
if (move == 2){
    Hero.itsXCoord -= 1;
}
if (move == 3){
    Hero.itsYCoord += 1;
}
if (move == 4){
    Hero.itsYCoord -= 1;
}

cout << "Currently you are at: " << Hero.getXCoord() << ", " << Hero.getYCoord();
}


I keep on getting a

1>one.obj : error LNK2019: unresolved external symbol "public: int __thiscall Character::getXCoord(void)" (?getXCoord@Character@@QAEHXZ) referenced in function "void __cdecl Move(void)" (?Move@@YAXXZ)


error.

I don't know why.

Please help me!
You did not provide function bodies for getXCoord() or getYCoord(), or any of the set functions. Provide function bodies (a. k. a. function definitions).
Last edited on
What function definitions should be there?
Last edited on
closed account (D80DSL3A)
You need to define what the functions do, like you have done for the Move() on lines 16-36.
Note: There is no need for set() and get()'s. The variables in your class have public access so you can use the values directly.
eg: instead of Hero.setXCoord(0);
You could assign directly: Hero.itsXCoord = 0;

Topic archived. No new replies allowed.