Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C++ Need help to understanding syntax of a parameter passed to a function vector<vector<int>> A[]

I am solving a question where a function is defined as following:

vector <int> func(int a, vector<vector<int>> B[]){
    // Some stuff
}

I am confused about why the second parameter is not only vector<vector> B why the extra [] part in the parameter. Can someone clarify the meaning of this parameter vector<vector> B[]?

The vector B is populated by a similar code snippet:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

vector<vector<int>> B[10]; 
while(num--){
    cin>>u>>v>>w;
    vector<int> t1,t2;
    t1.push_back(v);
    t1.push_back(w);
    B[u].push_back(t1);
    t2.push_back(u);
    t2.push_back(w);
    B[v].push_back(t2);
}

>Solution :

B ist a static array (C-style) of 10 elements [0 .. 9]. It’s not safe and this code is a terrible mess.
Better use std::array<std::vector<str::vector<int>>, 10> B; instead to have index checking.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading