tags:

views:

163

answers:

2

Please can anybody explain to me what this means?

vector<int> myvector(4,99);  
+11  A: 

It's (most likely) an std::vector of integers, initialized to contain four integers with the value of 99.

Matti Virkkunen
+10  A: 

A a(x,y); creates an object called a, calling a constructor of A with two parameters matching the types of x and y, or any convertible types.

So this:

vector<int> myvector(4,99);

Matches this constructor:

explicit vector( size_type num, const TYPE& val = TYPE() ); 
// `TYPE` is a `typedef` assigned to the parametrized type (here `int`), which means the constrcutor is actually:
explicit vector( size_type num, const int& val = int() );

Which constructs a vector with 4 elements of value 99 and calls it myvector. This constructor is called because the first parameter can be converted to a size_type, which is also a typedef, defined to an integral type (usually unsigned long).

Samuel_xL