Hi
Jaja, immer noch C++Neuling. Ich hatte erst vor kurzen einem Thread wegen Klassen, und hatte mir gedacht mittels Klassen eine art Bauernhof zu bastel xD
Leider gibt der Compiler Meldungen aus
(Sry, weniger ging nicht^^)
Meldungen:
[Linker error] undefined reference to `Bauernhof::Geld'
[Linker error] undefined reference to `Bauernhof::Schwein'
usw...
Wie umgehe ich das Problem?
Achja
Das
Funktioniert auch nicht 
Jaja, immer noch C++Neuling. Ich hatte erst vor kurzen einem Thread wegen Klassen, und hatte mir gedacht mittels Klassen eine art Bauernhof zu bastel xD
Leider gibt der Compiler Meldungen aus

(Sry, weniger ging nicht^^)
Code:
#include <iostream>
using namespace std;
//Klasse
class Bauernhof{
private:
static int Kuh;
static int Schwein;
static int Huhn;
static int Ksatt;
static int Ssatt;
static int Hsatt;
static int Heu;
static int Korner;
static int Milch;
static int Eier;
static int Fleisch;
static int Geld;
static int Gebiet;
public:
void kaufen(int was, int anzahl);
void schlachten(int was, int anzahl);
void verkaufen(int was, int anzahl);
void futtern(int was, int womit);
};
/*
***
Funktion Kaufen
***
*/
void Bauernhof::kaufen(int was, int anzahl){
/*
Kuh (1000€), Schwein(700€), Huhn(100€), Heu(50€/1kg), Korner(100€/1kg)
*/
switch (was){
case 1:
//Kuh
if (Geld >= 1000*anzahl){
Kuh += anzahl;
Geld -= 1000*anzahl;
}
else{
cout<<"Du hast nicht genung Geld\n";
}
break;
case 2:
//Schwein
if (Geld >= 700*anzahl){
Schwein += anzahl;
Geld -= 700*anzahl;
}
else{
cout<<"Du hast nicht genug Geld\n";
}
break;
case 3:
//Huhn
if (Geld >= 100*anzahl){
Huhn += anzahl;
Geld -= 100*anzahl;
}
else{
cout<<"Du hast nich genung Geld\n";
}
break;
case 4:
//Heu
if (Geld >= 50*anzahl){
Heu += anzahl;
Geld -= 50*anzahl;
}
else{
cout<<"Du hast nich genung Geld\n";
}
break;
case 5:
//Korner
if (Geld >= 100*anzahl){
Korner += anzahl;
Geld -= 100*anzahl;
}
else{
cout<<"Du hast nich genung Geld\n";
}
break;
}
}
Meldungen:
[Linker error] undefined reference to `Bauernhof::Geld'
[Linker error] undefined reference to `Bauernhof::Schwein'
usw...
Wie umgehe ich das Problem?
Achja
Code:
#include <iostream>
#include "Bauernhof.h"
using namespace std;
Code:
#include <iostream>
#ifndef __Bauernhof_H
#define __Bauernhof_H
Bauernhof::void kaufen(int was, int anzahl);
Bauernhof::void schlachten(int was, int anzahl);
Bauernhof::void verkaufen(int was, int anzahl);
Bauernhof::void futtern(int was, int womit);
#endif
#include "Bauernhof.h"
using namespace std;
