Moin zusammen,
also ich finde diesmal meinen error LNK2019 sehr kurios. Vorallem, weil ich die ganze Situation auch noch mal in einem neuen Projekt nachgestellt habe und dort hat es funktioniert. Aber vielleicht übersehe ich auch etwas.
Hier erst mal der Code:
|
C-/C++-Quelltext
|
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
|
/* Ship.h */
#ifndef SHIP_H
#define SHIP_H
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include "Weapon.h"
using namespace std;
typedef struct ShipDimension
{
int width, height;
} ShipDimension;
class Ship
{
public:
Ship( ShipDimension dimension, bool vertical, map<string, Weapon*> specialWeapons );
virtual ~Ship();
ShipDimension getDimension();
bool isVertical();
Weapon* getWeapon( string weaponName );
void useSpecialWeapon( string weaponName );
protected:
static int count;
ShipDimension dimension;
bool vertical;
map<string, Weapon*> specialWeapons;
};
#endif
|
|
C-/C++-Quelltext
|
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
|
/* GameField.h */
#ifndef GAMEFIELD_H
#define GAMEFIELD_H
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include "Field.h"
#include "Ship.h"
using namespace std;
class GameField
{
public:
GameField(int fieldCount);
~GameField();
bool addShip(const Ship* ship, const int startField);
int* getShipFields(const int shipStartField);
protected:
vector<Field*> fields;
map<int, Ship*> ships;
};
#endif
|
Wenn ich das ganze kompeliere, dann erhalte ich folgende Fehlermeldung: GameField.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: struct ShipDimension __thiscall Ship::getDimension(void)" (?getDimension@Ship@@QAE?AUShipDimension@@XZ)" in Funktion ""public: bool __thiscall GameField::addShip(class Ship const *,int)" (?addShip@GameField@@QAE_NPBVShip@@H@Z)".
Hier der Code von der Methode addShip:
|
C-/C++-Quelltext
|
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
bool GameField::addShip(const Ship* ship, const int startField)
{
map<int, Ship*>::iterator f = ships.find( startField );
if( f != ships.end() ) return true;
ships[startField] = (Ship*)ship;
int* shipFields = getShipFields(startField);
string lastLetter = fields[startField-1]->getFieldName().substr(0, 1);
string lastNumber = fields[startField-1]->getFieldName().substr(1, 1);
#ifdef _DEBUG
cout << "Last letter: " << lastLetter << endl;
cout << "Last number: " << lastNumber << endl;
#endif
for( int i = 0; i < ships[startField]->getDimension().width; ++i )
{
// Check if there is no other ship on the same field
if( fields[shipFields[i]-1]->hasShip() )
{
cout << "Error: Ship can not be placed, other ship is on field!" << endl;
ships.erase(startField);
return false;
}
// Check if the ship is placed that it hasn't any part in the next colum or row
if( ships[startField]->isVertical() )
{
string currentNumber = fields[shipFields[i]-1]->getFieldName().substr(1, 1);
if( currentNumber != lastNumber )
{
cout << "Error: Ship can not be placed here!" << endl;
ships.erase(startField);
return false;
}
}
else
{
string currentLetter = fields[shipFields[i]-1]->getFieldName().substr(0, 1);
if( currentLetter != lastLetter )
{
cout << "Error: Ship can not be placed here!" << endl;
ships.erase(startField);
return false;
}
}
}
for( int i = 0; i < ships[startField]->getDimension().width; ++i )
fields[shipFields[i]-1]->setHasShipPart();
#ifdef _DEBUG
cout << "---------------------SHIPS--------------------" << endl;
for( map<int, Ship*>::iterator it = ships.begin();
it != ships.end();
++it )
{
Ship* s = it->second;
cout << "Ship on fields: ";
int* fs = getShipFields(it->first);
for(int i = 0; i < s->getDimension().width; ++i)
cout << fs[i] << "|" << fields[fs[i]-1]->getFieldName() << " ";
cout << endl;
cout << " Dimension: " << s->getDimension().width << "x" << s->getDimension().height << endl;
cout << " Vertical: " << boolalpha << s->isVertical() << endl;
}
cout << "---------------------SHIPS--------------------" << endl;
#endif
return true;
}
|
Danke schon mal im Voraus!