我試圖設置長度並啓動類的向量成員。但它似乎是唯一可能的,如果初始化線是在課外。 你喜歡什麼? (感謝)初始化C++中的向量類成員
//a vector, out of class set size to 5. initilized each value to Zero
vector<double> vec(5,0.0f);//its ok
class Bird{
public:
int id;
//attempt to init is not possible if a vector a class of member
vector<double> vec_(5, 0.0f);//error: expected a type specifier
}
在C++ 11中,您可以擁有默認的成員值,但不能在C++ 98中使用。語法是'vector vec_ = vector (5,0.0f);' –
Franck