如何在构造函数中初始化向量?我想在构造函数Doom
中初始化 vector属性,但出现此错误:
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: