请任何人向我解释这意味着什么?
vector<int> myvector(4,99);
它(最有可能是)一个std :: vector整数,被初始化为包含四个值为99的整数。
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
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.