Enum Get-Funktion
-
Warum kriege ich den Error : "City Does Not Name A Type" ??? habe das gefühl der Kompiler will mich ärgern ich sehe absolut keinen Grund Warum meine Get-Funktion für enum City nicht funktionieren sollte
Header File:#include "Customer.h" #ifndef BIKE_H #define BIKE_H class Bike { public: enum City {Bensheim, Darmstadt, Heppenheim} ; Bike(string description, City city); Bike(const Bike& orig); virtual ~Bike(); string GetDescription() const; Customer* GetCustomer() const; string GetCode() const; void SetCustomer(Customer* customer); City GetCity() const; private: City city; string code; Customer* customer; string description; }; #endif /* BIKE_H */Und die .cpp File:
#include "Bike.h" Bike::Bike(string description, City city) { customer=NULL; code=(rand()+time(0))%100000; } void Bike::SetCustomer(Customer* customer) { this->customer = customer; } City Bike::GetCity() const{ return city; } Bike::Bike(const Bike& orig) { } Bike::~Bike() { } string Bike::GetDescription() const { return description; } Customer* Bike::GetCustomer() const { return customer; } string Bike::GetCode() const { return code; }Über eine Antwort würde ich mich freuen.
-
Lapa1503 schrieb:
Warum kriege ich den Error : "City Does Not Name A Type" ??? habe das gefühl der Kompiler will mich ärgern ich sehe absolut keinen Grund Warum meine Get-Funktion für enum City nicht funktionieren sollte
Dann lies ein Buch. Ich erkenne schon einen Grund...
-
C++ ist da leider pedantisch und besteht darauf es so zu schreiben:
Bike::City Bike::GetCity() const{ return city; }
-
Ah super das wusste ich leider nicht . Danke für die Hilfe

-
Außerdem ignorierst du die Parameter des Konstruktors.
-
TyRoXx schrieb:
C++ ist da leider pedantisch und besteht darauf es so zu schreiben:
Bike::City Bike::GetCity() const{ return city; }auto Bike::GetCity() const -> City { return city; }wäre auch möglich. Der Grund, weshalb im 1. Fall der Name City mit Bike:: qualifiziert werden muss, liegt darin, dass der Compiler erst, nachdem er den Bezeichner Bike::GetCity gesehen hat, weiss, dass es sich um eine Definition dieses Klassenmembers handelt, und somit alle folgenden Bezeichner (also die der Parameterliste und folgende) in dieser Deklaration beginnend im Namensraum der Klasse gesucht werden müssen. Das Bike in Bike::City und Bike::GetCity hingegen wird im globalen Namensraum gesucht (und dort gibt es keinen Bezeichner City).