jeudi 21 mai 2020

Passing array of vectors by reference in C++

In the main function, I defined an array of vectors like this:

vector<int> v[n+1];

where n is taken from stdin.

In the main function, I am calling a function passing this argument like this:

   func(v); 

In the function definition, I defined it this way:

func(vector<int>& v[])        # I want to pass v as reference.

On compiling using g++ --std=c++11 a.cpp, I am getting this error:

error: 'v' declared as array of references of type 'vector<int> &'

Any help would be highly appreciated.

Aucun commentaire:

Enregistrer un commentaire