Can’t resolve Error: indirection requires pointer operand (‘int’ invalid)

I created a vector of vertex pointers and now I want to print them out. I tried to print them out by dereferencing the pointers, but that didn’t work and I got Error: indirection requires pointer operand ('int' invalid). I’ve printed out pointers before, but I have never run into this error. Any help would be great! Thanks in advance!

vector<Vertex*> vertices (numVertices + 1);

for(int i=1;i<=numVertices;i++)
{   
    file >> numEdges;
    cout << "At vertex " << i << " the number of edges is " << numEdges << endl;
    vertices[i] = new Vertex();
    //Vertex newVertex;

    //Using the i counter variable in the outer for loop to identify
    //the what vertex what are currently looking at in order to read in the correct adjacent vertex and weight
    vertices[i] -> setVertexNum(i);
    //newVertex.setVertexNum(i);

    for(int j=1;j<=numEdges;j++)
    {
        file >> adjacentVertex;
        cout << "The adjacent vertex is: " << adjacentVertex << endl;

        file >> weight;
        cout << "The weight is: " <<  weight << endl;
        cout << endl;

        vertices[i]->setAdjacentVertex(adjacentVertex, weight);
    }
    vertices.push_back(vertices[i]);
}
vector<Vertex*> sortedVertices = vertices;
insertionSort(sortedVertices);

for(int i=0;i<vertices.size();i++)
{
    cout << "V" << i << ":  ";
    cout << endl;

Leave a Comment