C++ // Unschlüssige Fehlermeldung

Code:
/*
 * kfz.h
 *
 *  Created on: 03.10.2009
 *      Author: erteet
 */

#ifndef KFZ_H_
#define KFZ_H_

#include <iostream>
#include <string>
#include "wohn.h"

using namespace std;

class Kfz
{
	private:
		long nr;
		string hersteller;

	public:
		Kfz( long n = 0L, const string& herst = "");
		virtual ~Kfz();
		long getNr() { return nr;}
		void setNr( long n ) { 	nr = n;}

		const string& getHerst() const{return hersteller;}
		void setHerst(const string& h){ hersteller = h;}

		virtual void display(void) const;
};

class Pkw : public Kfz
{
	private:
		string pkwTyp;
		bool schiebe;

	public:
		Pkw(const string& tp, bool sd, long = 0, const string& h = "");
		~Pkw();

		const string& getTyp() const {return pkwTyp;}
		void setTyp(const string s){pkwTyp = s;}

		bool getSchiebe() const {return schiebe;}
		void setSchiebe( bool b){ schiebe = b;}
		void display() const;

};

class Lkw : public Kfz
{
	private:
		int anzAchsen;
		double maxLade;

	public:

		Lkw(int anz = 0, double max = 0.0, long n = 0L, const string& hr = "");
		~Lkw();

		void setAchsen(int anz){ anzAchsen = anz;}
		int getAchsen(void) const{ return anzAchsen;}

		void setKapazitaet(double max){ maxLade = max;}
		double getKapazitaet(void) const{ return maxLade ;}

		void display(void) const;
};


#endif /* KFZ_H_ */





/*
 * wohn.cpp
 *
 *  Created on: 08.10.2009
 *      Author: erteet
 */

#include "wohn.h"

void Wohnung::display() const
{
	cout << "Zimmer: " << anzZimmer << endl
		 << "Quadratmeter: "<< qMeter << endl;

}


void Wohnwagen::display() const
{
	cout << "Wohnwagen:\n";
	Kfz::display();
	Wohnung::display();

	cout << "Kategorie: ";
	switch(kat){
		case EINFACH:
			cout << "einfach";
			break;
		case LUXUS:
			cout << "luxoriös";
			break;
		case MITTEL:
			cout << "mittelmäßig";
			break;
		case GEHOBEN:
			cout << "gehoben";
			break;
		}
		cout << endl;
}

/*
 * wohn.h
 *
 *  Created on: 08.10.2009
 *      Author: erteet
 */

#ifndef WOHN_H_
#define WOHN_H_

#include <string>
#include <iostream>
using namespace std;

enum KATEGORIE {LUXUS, GEHOBEN, MITTEL, EINFACH};

class Wohnung
{
	private:

		int anzZimmer;
		int qMeter;


	public:


		Wohnung(int anz = 0, int m = 0)
		: anzZimmer(anz), qMeter(m)
		{}

		void setAnzZimmer(int anz){ anzZimmer = anz;}
		int getAnzZimmer(void) const{ return anzZimmer;}

		void setQMeter(int m){ qMeter = m;}
		int getQMeter(void) const{return qMeter;}

		void display()const;

};


class Wohnwagen : public Kfz, public Wohnung
{
	private:
		KATEGORIE kat;

	public:
		Wohnwagen(long n = 0L, const string& hr = "", int anz = 0, int m = 0, KATEGORIE k = EINFACH)
			: Kfz(n, hr), Wohnung(anz, m) kat(k){}

		void setKategorie(KATEGORIE k){ kat = k;}
		KATEGORIE getKategorie() const { return kat;}

		void display() const;
};

#endif /* WOHN_H_ */

/*
 * kfz.cpp
 *
 *  Created on: 03.10.2009
 *      Author: erteet
 */

#include "kfz.h"
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

Pkw::Pkw(const string& tp, bool sd, long n, const string& hr)
	: Kfz(n, hr), pkwTyp(tp), schiebe(sd)
{
	cout << "Ich baue ein Objekt vom Typ Pkw auf." << endl;
}

Kfz::Kfz(long n, const string& hr)
{
	cout << "Ich baue ein Objekt vom Typ Kfz auf." << endl;
	nr = n;
	hersteller = hr;
}

Kfz::~Kfz()
{
	cout << "Ich zerstöre ein Objekt vom Typ Kfz.\n";
}

Pkw::~Pkw()
{
	cout << "Ich zerstöre ein Objekt vom Typ Pkw." << endl;
}

void Kfz::display(void) const
{
	cout << "Hersteller: " << hersteller << endl
		 << "Nr: " << nr << endl;
}

void Pkw::display (void)const
{
	Kfz::display();

	cout << "PkwTyp: " << pkwTyp << endl;
	cout << "Schiebedach: ";
	if(schiebe)
		cout << "ja\n";
	else
		cout << "nein\n";
}

Lkw::Lkw(int anz, double max, long n, const string& hr)
	: Kfz(n, hr), anzAchsen(anz), maxLade(max)
{
	cout << "Ich erzeuge ein Objekt vom Typ Lkw.\n";
}

Lkw::~Lkw()
{
	cout << "Ich zerstöre ein Objekt vom Typ Lkw.\n";
}

void Lkw::display(void) const
{
	Kfz::display();

	cout << "Ladekapazität in Tonnen: " << maxLade << endl;
	cout << "Achsen :" << anzAchsen << endl;
}
Compilermeldung:
Code:
make all 
Building file: ../kfz.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"kfz.d" -MT"kfz.d" -o"kfz.o" "../kfz.cpp"
In file included from ../kfz.h:13,
                 from ../kfz.cpp:8:
../wohn.h:43: Fehler: expected class-name before ?,? token
../wohn.h: In constructor ?Wohnwagen::Wohnwagen(long int, const std::string&, int, int, KATEGORIE)?:
../wohn.h:50: Fehler: Klasse ?Wohnwagen? hat keinen Feldnamen ?Kfz?
../wohn.h:50: Fehler: expected `{' before ?kat?
make: *** [kfz.o] Fehler 1

Irgendwie aktzepiert er Kfz nicht als richtige Klasse, kann mir aber nicht erklären warum.

Einer ne Idee?
 
Code:
Pkw(const string& tp, bool sd, long = 0, const string& h = "");
Da fehlt doch ein Name (bei long)?

mfg benediktibk
 
Spontan würde ich vermuten, er kennt die Klasse Kfz dort nicht, weil es sie in seinem Kontext auch nicht gibt. Du solltest mal die Headerdatei includen.
 
Reicht wenn wohn.h in kfz.h included wird, habs auch sicherheitshalber nocheinmal getestet, ändert aber leider nichts an der Fehlermeldung
 
In wohn.h muss kfz.h includiert werden, also andersrum. Aber wie gesagt, ich bin nicht sicher, nur scheint mir das bald so zu sein. Ggf. würde auch eine stupide Klassendefinition reichen.
 
Zurück
Oben