PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, December 14, 2022

[FIXED] what does vector<int> dist(n, INT_MAX); mean in C++?

 December 14, 2022     c++, constructor, syntax     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing