如何在构造函数中初始化向量?

时间:2019-07-01 17:47:39

标签: c++11

如何在构造函数中初始化向量?我想在构造函数Doom中初始化 vector属性,但出现此错误:

在抛出'std :: bad_alloc'实例后调用

terminate what():std :: bad_alloc

//。h

class Doom
{
    public:
        Doom(std::string  label,  vector<std::string> * properties);

//。h

class Div:public Doom
{
public:
    Div();
    string addPropertie(string );
    vector<std::string> *c;

    string d;
protected:

private:
};

//。cpp

Div::Div():Doom(Div::d, Div::c)
{
cout<<"DIV"<<endl;
}

要初始化矢量,我可以尝试以下方法:

public:
    Div();
    string addPropertie(string );
    vector<std::string> *c;


    for (int i = 1; i <= 5; i++)
        c.push_back("s");
    string d;
protected:

0 个答案:

没有答案