rozina
rozina

Reputation: 4232

Calling member constructor in class definition

struct Foo
{
    std::vector<int> vec = {5, 123};
};

The above code initializes the vector with two elements (5 and 123). How can I call the constructor that takes size and initial value - the equivalent of std::vector<int> vec(5, 123).

Upvotes: 3

Views: 101

Answers (1)

juanchopanza
juanchopanza

Reputation: 227370

You can use this form, for which the std::initializer_list constructor does not participate in overload resolution:

std::vector<int> vec = std::vector<int>(5, 123);

Upvotes: 4

Related Questions