erotavlas
November 17th, 2010, 10:43 AM
Hi,
I have the following class.
class Auto {
public:
enum AUTO_TYPE {SPORT, STANDARD};
enum PROBLEM_TYPE {COMBUSTION, ELECTRIC};
Auto(const std::string& autoType_, const std::string& engineType_) {
// sets the flags
if (autoType_ == "SPORT")
autoType = SPORT;
else (autoType_ == "STANDARD")
autoType = STANDARD;
if (engineType_ == "COMBUSTION")
engineType = COMBUSTION;
else (engineType_ == "ELECTRIC")
engineType = ELECTRIC;
}
private:
AUTO_TYPE autoType;
ENGINE_TYPE engineType;
};
The private members are initialized by the constructor and they are read from input stream. I would like to know if is a good idea to make the conversion from string type to enum inside the constructor. Is there a better way to do it?
Thank you
I have the following class.
class Auto {
public:
enum AUTO_TYPE {SPORT, STANDARD};
enum PROBLEM_TYPE {COMBUSTION, ELECTRIC};
Auto(const std::string& autoType_, const std::string& engineType_) {
// sets the flags
if (autoType_ == "SPORT")
autoType = SPORT;
else (autoType_ == "STANDARD")
autoType = STANDARD;
if (engineType_ == "COMBUSTION")
engineType = COMBUSTION;
else (engineType_ == "ELECTRIC")
engineType = ELECTRIC;
}
private:
AUTO_TYPE autoType;
ENGINE_TYPE engineType;
};
The private members are initialized by the constructor and they are read from input stream. I would like to know if is a good idea to make the conversion from string type to enum inside the constructor. Is there a better way to do it?
Thank you