PDA

View Full Version : How to solve "does not name a type error"



NtobekoQt
24th April 2014, 01:15
Hi there please help after trying to run the code below I got the error: 'FCType' does not name a type

header file


#ifndef FREIGHTCAR_H
#define FREIGHTCAR_H

#include <QString>

class FreightCar
{

private:
QString ID;
double tonnage;
protected:
enum FCType {ALL, BOX, GONDOLA, TANK, FLATBED};
FCType type;
public:
FreightCar(QString id, double t);
QString getID() const;
double getTonnage();
double setTonnage(double t);
FCType getType() const;
QString toString()const;




};
#endif // FREIGHTCAR_H

.cpp file


#include "freightcar.h"

FreightCar::FreightCar(QString id, double t)
: ID(id), tonnage(t) { }

QString FreightCar::getID() const{
return ID;
}
double FreightCar::getTonnage(){
return tonnage;
}
double FreightCar::setTonnage(double t){
return tonnage = t;
}
FCType FreightCar::getType() const{
return type;
}
QString FreightCar::toString() const{
return QString("Freight car: \nID: %1, %2 \nTonnage: %3 \nFreight car type: %4")
.arg(ID)
.arg(tonnage)
.arg(type);
}

ChrisW67
24th April 2014, 02:43
The getType() return type is FreightCar::FCType, there is no FCType in global scope..
The issue then becomes that the enum is declared protected so it is not useful as the return value of a public function: make the enum declaration public.

BTW: Your constructor should initialise the type member variable.