dimanche 1 novembre 2015

How to pass an Array of vectors in C++?

#include <string>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <array>

using namespace std;
int n=0;
void chk(array<std::vector<int>, 4>& send)
{
    int i,j;
    for(i=1;i<=n;i++)
    {
        cout<<"\nadjacenecy list of "<<i<<": ";
        for(j=0;j<send[i].size();j++)
        {
            cout<<send[i][j]<<" ";
        }
    }
}
int main() {
// your code goes here
int x,y,m;
cin>>n>>m;

vector<int> send[n+1];
for(int i=0;i<m;i++)
{
    cin>>x>>y;
    send[x].push_back(y);
    send[y].push_back(x);
}
chk(send);
return 0;
}

It is giving the error

prog.cpp:33:10: error: invalid initialization of non-const reference of type 'std::array<std::vector<int>, 4u>&' from an rvalue of type 'std::vector<int>*'
  chk(send);

WHAT SHOULD I DO?

Aucun commentaire:

Enregistrer un commentaire