错误的方法
class Foo {
private:
vector<string> name(5); //error in these 2 lines
vector<int> val(5, 0);
};
正确的方法
C++11以后:
class Foo {
private:
vector<string> name = vector<string>(5);
vector<int> val{vector<int>(5, 0)};
};
C++11以前:
class Foo {
private:
vector<string> name;
vector<int> val;
public:
Foo() : name(5), val(5, 0) {}
};