我正在努力解决错误,我一直无法找到解决方案。我似乎无法理解为什么“位置”不是作为一个班级找到的。这里是我的头文件:不是类或名称空间错误
#ifndef CLASS2_HPP
#define CLASS2_HPP
class Passenger
{
public:
enum class Location
{
Business,
Economy,
Vip
};
Passenger(Location clas_s, char* firstName, char* secondName, int seat, int terminal, float time_of_departure);
const char* get_location() const;
int get_seat() const;
int get_terminal() const;
float get_time() const;
char* get_firstName() const;
char* get_secondName() const;
void print() const;
private:
Location _clas_s;
char _firstName;
char _secondName;
int _seat;
int _terminal;
float _time_of_departure;
};
#endif // CLASS2
这里是我的CPP文件:
#include <iostream>
#include "Class2.hpp"
using namespace std;
Passenger::Passenger(Location clas_s, char* firstName, char* secondName, int seat, int terminal, float time_of_departure)
: _clas_s(clas_s), _firstName(firstName), _secondName(secondName), _seat(seat), _terminal(terminal), _time_of_departure(time_of_departure) {};
void Passenger::print() const
{
cout << "Your name is " << _firstName
<< " " << _secondName << endl
<< "Your class is " << get_location() << endl
<< "Your seat is " << _seat << endl
<< "Your terminal is " << _terminal << endl
<< "Your time of departure is " << _time_of_departure << endl;
}
const char* Passenger::get_location() const
{
switch (_clas_s)
{
case Location::Business : return "Business";
case Location::Economy : return "Economy";
case Location::Vip : return "Vip";
}
}
int main() {
Passenger p((Passenger::Location::Vip), 'John', 'Johnson', 25, 2, 13.53);
p.print();
return 0;
}
在此先感谢。
就在我头上:您可能想要使用Passenger :: Location – Alain
您在哪一行发生错误? – aschepler
行是24/25/26/32 –