查找表错误:无法转换'<brace-enclosed initializer =“”list =“”>'

时间:2018-04-19 13:44:01

标签: c++ oop

我想为查找表初始化的汽车创建类,但我有这样的错误:错误:无法将'{“Lambordgini Murcielago”,0,670,0}从''转换为'汽车'  };

这是我的源代码:

class Cars
{
public:
enum Type
{
    Lambordgini = 0,
    Mercedes,
    Pagani,
    Bugatti,
    MAX_TYPES
};

Cars(Type type):m_name(carInfo[type].m_name),m_id_number(carInfo[type].m_id_number),
        m_hs_power(carInfo[type].m_hs_power), m_reg_number(carInfo[type].m_reg_number)
        {};

uint16_t getHorsePower() const;
uint16_t getIdNumber() const;
uint16_t getNumber() const;
const std::string& getName() const;

static Cars carInfo[MAX_TYPES];

private:

std::string m_name;
uint16_t m_id_number;
uint16_t m_hs_power;
uint16_t m_reg_number;

};

Cars Cars::carInfo[Cars::MAX_TYPES]
{
    {"Lambordgini Murcielago", 0, 670, 0000},
    {"Mercedes-AMG", 1, 503, 0000},
    {"Pagani Zonda R", 2, 740, 0000},
    {"Bugatti Veyron", 3, 1020,0000},
};

0 个答案:

没有答案