Hallo miteinander,
ich muss C++-Aufgaben erstellen, die zum Thema Wintersport passen. Daher
hat der folgende Code eigentlich keinen richtigen Zweck, muss aber ja
trotzdem funktionieren.
Ich habe zwei Klassen geschrieben, die voneinander abhängig sind, was
irgendwie nicht richtig funktioniert, denn ich erhalte beim Versuch, die
main zu kompilieren, die Fehlermeldung, die ich im Code markiert habe.
Hier die zwei Headerdateien und der Versuch, die main anzufangen:
Bob.h
1 | #include <iostream>
|
2 | #include <Fahrer.h>
|
3 | using namespace std;
|
4 |
|
5 | class Bob
|
6 | {
|
7 | friend class Fahrer;
|
8 |
|
9 | private:
|
10 | bool sitzplatz[4];
|
11 | Fahrer sitz[4]; <--- Bob.h:27:15: Fehler: Feld »sitz« hat unvollständigen Typen
|
12 | int gewicht;
|
13 |
|
14 | public:
|
15 | Bob ()
|
16 | {
|
17 | gewicht = 40; // Leergewicht eines Bobs;
|
18 |
|
19 | for (int i = 0; i < 4; i++)
|
20 | sitzplatz[i] = false;
|
21 | }
|
22 |
|
23 | int getGewicht () const {return gewicht;}
|
24 |
|
25 | string getName (int i)
|
26 | {
|
27 | if (sitzplatz[i]) return sitz[i].getName();
|
28 | else return "";
|
29 | }
|
30 |
|
31 | Bob operator+= (const Bob *zusteiger);
|
32 | {
|
33 | for (int i = 0; i < 4; i++)
|
34 | {
|
35 | if (sitzplatz[i] == false)
|
36 | {
|
37 | sitz[i] = *zusteiger;
|
38 | sitz[i] = true;
|
39 | gewicht += (*zusteiger).getGewicht();
|
40 | break;
|
41 | }
|
42 | }
|
43 | }
|
44 |
|
45 | Bob operator-- ();
|
46 | {
|
47 | for (int i = 3; i >= 0; i--)
|
48 | {
|
49 | if (sitzplatz[i] == true)
|
50 | {
|
51 | sitzplatz[i] == false;
|
52 | gewicht -= sitz[i].getGewicht();
|
53 | break;
|
54 | }
|
55 | }
|
56 | }
|
57 |
|
58 | bool operator== (const Bob *fahrer1, const Bob *fahrer2) const
|
59 | {
|
60 | if ( (*fahrer1).getName() == (*fahrer2).getName() ) return true;
|
61 | else return false;
|
62 | }
|
63 | };
|
Fahrer.h
1 | #include <iostream>
|
2 | #include <Bob.h>
|
3 | using namespace std;
|
4 |
|
5 | class Fahrer
|
6 | {
|
7 | private:
|
8 | string name;
|
9 | int gewicht;
|
10 | int groesse;
|
11 |
|
12 | public:
|
13 | Fahrer () {};
|
14 |
|
15 | string getName () const {return name;}
|
16 | int getGewicht () const {return gewicht;}
|
17 | int getGroesse () const {return groesse;}
|
18 |
|
19 | void setName (string _name) {name = _name;}
|
20 | void setGewicht (int _gewicht) {gewicht = _gewicht;}
|
21 | void setGroesse (int _groeses) {groesse = _groesse;}
|
22 |
|
23 | void Aussteigen (Bob rennbob)
|
24 | {
|
25 | for (int i = 0; i < 4; i++)
|
26 | if (*this == sitz[i])
|
27 | {
|
28 | sitzplatz[i] = false;
|
29 | Bob::gewicht -= this->gewicht;
|
30 | }
|
31 | }
|
32 |
|
33 | bool Einsteigen (Bob rennbob)
|
34 | {
|
35 | for (int i = 0; i < 4; i++)
|
36 | if (sitzplatz[i] == false)
|
37 | {
|
38 | sitzplatz[i] = true;
|
39 | sitz[i] = this;
|
40 | Bob::gewicht += this->gewicht;
|
41 | return true;
|
42 | }
|
43 | }
|
44 | };
|
main.cpp
1 | class Fahrer;
|
2 | class Bob;
|
3 |
|
4 | #include "Bob.h"
|
5 | #include "Fahrer.h"
|
6 | #include <iostream>
|
7 | using namespace std;
|
8 |
|
9 | int main()
|
10 | {
|
11 |
|
12 | }
|
Wäre super, wenn jemand eine Idee hat, was falsch ist. Ich befürchte ja,
dass es etwas sehr einfaches ist... ^^
Danke im Vorraus für jede Mühe.
Grüße, Kay