I want to declare a vector of 2 elements as a class member. But next code generates an error:
class A { private: std::vector v (2); ... }
You can safely use this syntax:
std::vector v = std::vector(2);
Alternatively, use brace initialization, but you must be careful: the std::initializer_list constructor will be picked, so to initialize a vector with two value- (therefore zero-) initialized ints you need
std::initializer_list
ints
std::vector v{0, 0};