Programmiere schon ne Weile in C , und hab vor kurzem angefangen mich mit OOP zu beschäftigen.
Kurzum habe vor C++ zu lernen und hab nen kleines Problem hier mal die sources ^^
kfz.h:
kfz.cpp
Der Code sollte meiner Meinung nach vollkommen in Ordnung sein, ist auch großteils ausm Buch aber eclipse / gcc gibt mir folgende Fehlermeldungen aus
expected `{' before ?.? token
expected unqualified-id before ?.? token
in Zeile 31 das entspräche
class Pkw : public Kfz
Fehlermeldung sieht mitlerweile so aus
erteet@Logic:~/coding/workspace/Kfz-Verwaltung$ g++ -o kfz kfz.cpp kfz_t.cpp
In file included from kfz.cpp:8:
kfz.h:42: Fehler: zusätzliche Qualifizierung ?Pkw::? an Element ?Pkw?
kfz.cpp:14: Fehler: redefinition of ?Pkw:
kw(const std::string&, bool, long int, const std::string&)?
kfz.h:42: Fehler: ?Pkw:
kw(const std::string&, bool, long int, const std::string&)? wurde vorher hier definiert
In file included from kfz_t.cpp:8:
kfz.h:42: Fehler: zusätzliche Qualifizierung ?Pkw::? an Element ?Pkw?
kfz_t.cpp: In function ?int main()?:
kfz_t.cpp:18: Fehler: keine passende Funktion für Aufruf von ?Pkw:
kw(const char [8], bool)?
kfz.h:42: Anmerkung: Kandidaten sind: Pkw:
kw(const std::string&, bool, long int, const std::string&)
kfz.h:36: Anmerkung: Pkw:
kw(const Pkw&)
Kurzum habe vor C++ zu lernen und hab nen kleines Problem hier mal die sources ^^
kfz.h:
Code:
/*
* kfz.h
*
* Created on: 03.10.2009
* Author: erteet
*/
#ifndef KFZ_H_
#define KFZ_H_
#include <iostream>
#include <string>
using namespace std;
class Kfz
{
private:
long nr;
string hersteller;
public:
Kfz(long n = 0L, const string& hr = "");
long getNr(void) const { return nr;}
void setNr(long n){ nr = n;}
void setHerst(const string& hr){ hersteller = hr; }
const string& getHerst(void) const { return hersteller;}
void display(void);
};
class Pkw : public Kfz
{
private:
bool schiebe;
string pkwTyp;
public:
Pkw(const string& tp, bool sd, long n = 0L, const string& hr="");
void setSchiebe(bool b){ schiebe = b;}
bool getSchiebe(void) const { return schiebe;}
void setTyp(const string& tp){ pkwTyp = tp;}
const string& getTyp(void) const { return pkwTyp;}
void display(void) const;
};
#endif /* KFZ_H_ */
Code:
/*
* kfz.cpp
*
* Created on: 03.10.2009
* Author: erteet
*/
#include "kfz.h"
Pkw::Pkw(const string& tp, bool sd, long n, const string& hr)
: Kfz(n, hr), pkwTyp(tp), schiebe(sd){}
Kfz::Kfz(long n = 0L, const string& hr = "")
{
nr = n;
hersteller = hr;
}
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";
}
Der Code sollte meiner Meinung nach vollkommen in Ordnung sein, ist auch großteils ausm Buch aber eclipse / gcc gibt mir folgende Fehlermeldungen aus
expected `{' before ?.? token
expected unqualified-id before ?.? token
in Zeile 31 das entspräche
class Pkw : public Kfz
Fehlermeldung sieht mitlerweile so aus
erteet@Logic:~/coding/workspace/Kfz-Verwaltung$ g++ -o kfz kfz.cpp kfz_t.cpp
In file included from kfz.cpp:8:
kfz.h:42: Fehler: zusätzliche Qualifizierung ?Pkw::? an Element ?Pkw?
kfz.cpp:14: Fehler: redefinition of ?Pkw:

kfz.h:42: Fehler: ?Pkw:

In file included from kfz_t.cpp:8:
kfz.h:42: Fehler: zusätzliche Qualifizierung ?Pkw::? an Element ?Pkw?
kfz_t.cpp: In function ?int main()?:
kfz_t.cpp:18: Fehler: keine passende Funktion für Aufruf von ?Pkw:

kfz.h:42: Anmerkung: Kandidaten sind: Pkw:

kfz.h:36: Anmerkung: Pkw:
