Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

DJSebi

Frischling

  • »DJSebi« ist der Autor dieses Themas

Beiträge: 19

Wohnort: KÖLN!!!!!

Beruf: Musiker, Informatiker, DJ, Moderator

  • Private Nachricht senden

1

29.11.2009, 16:28

error LNK2019 - Sehr kurios

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!

2

29.11.2009, 16:40

Wo ist den getDimension () implementiert ?

DJSebi

Frischling

  • »DJSebi« ist der Autor dieses Themas

Beiträge: 19

Wohnort: KÖLN!!!!!

Beruf: Musiker, Informatiker, DJ, Moderator

  • Private Nachricht senden

3

29.11.2009, 16:47

In der Klasse Ship?

DJSebi

Frischling

  • »DJSebi« ist der Autor dieses Themas

Beiträge: 19

Wohnort: KÖLN!!!!!

Beruf: Musiker, Informatiker, DJ, Moderator

  • Private Nachricht senden

4

29.11.2009, 16:50

Hmmm, okay... Ich muss wohl total vergessen habe die Methode getDimension auch zu implementieren... :oops:

Danke für den Hinweis!

Haxx0r

Treue Seele

Beiträge: 209

Wohnort: Da!

Beruf: Rebell mit aktivem Lebensstil

  • Private Nachricht senden

5

29.11.2009, 16:52

Zeig mal die komplette Ship-Klasse, sieht so aus als hättest du die Methoden nicht definiert.

6

29.11.2009, 16:54

ähm,
erstens mal glaub ich, du meinst implementiert, dann siehe mal 2 posts nach oben

Zitat

Wo ist den getDimension () implementiert ?


oder du meinst deklariert, und siehe hier:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Ship
{
public:
    Ship( ShipDimension dimension, bool vertical, map<string, Weapon*> specialWeapons );
    virtual ~Ship();

    ShipDimension    getDimension(); <--------------- DAAA
    bool            isVertical();
    Weapon*            getWeapon( string weaponName );
    void            useSpecialWeapon( string weaponName );

protected:
    static int count;
    ShipDimension dimension;
    bool vertical;
    map<string, Weapon*> specialWeapons;
}; 

DJSebi

Frischling

  • »DJSebi« ist der Autor dieses Themas

Beiträge: 19

Wohnort: KÖLN!!!!!

Beruf: Musiker, Informatiker, DJ, Moderator

  • Private Nachricht senden

7

29.11.2009, 17:47

Jo, ich sagte ja, ich habe sie total vergessen zu "implementieren", aber "definiert" hatte ich sie ja...

Ich sah es erst dann, als ich den hinweis von E122 las. Vielen Dank noch mal. Hatte den Code vor lauter Code nicht mehr gesehen...

8

29.11.2009, 19:12

Eine Funktionsdeklaration ist sowas:

C-/C++-Quelltext

1
int Square(int Value);

Eine Definition hingegen sieht so aus:

C-/C++-Quelltext

1
2
3
4
int Square(int Value)
{
    return Value * Value;
}

dot

Supermoderator

Beiträge: 9 757

Wohnort: Graz

  • Private Nachricht senden

9

29.11.2009, 20:57

Und wenn mans noch genauer nimmt ist eine Definition auch eine Deklaration aber nicht unbedingt umgekehrt :>

Werbeanzeige