Issue
i am new to C++ and I was wondering what the below code does. I tried googling but could not find the answer. Thanks
vector<int> dist(n, INT_MAX);
Solution
The line of code serves to declare a variable called dist
, and to initialise it is a std::vector
object.
The <int>
part of the vector initialisation is called a template argument. The std::vector
class is templated, which means it can store any arbitrary data-type, which is why the type has to be declared within angled brackets <>
.
As mentioned in the comments, n
and INT_MAX
are values being passed to one of the constructors of the std::vector
. It is only one of the constructors, since there are various different overloads of the constructor (check out the documentation in the comments to your question to read about the different available constructors).
Function (and also method) overloading is when you declare various functions with the same name, but that differ in the number and/or types of parameters that can be passed to them (the return type can also vary).
Answered By - htmlqueen Answer Checked By - Timothy Miller (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.