Question

$ make -f makefile.txt
g++ -Wall -W -Werror -pedantic -g -c MinPriority.cpp
MinPriority.cpp: In member function `void MinPriority::createArray()':
MinPriority.cpp:50: error: expected primary-expression before '&' token
MinPriority.cpp:50: error: expected primary-expression before ',' token
MinPriority.cpp:50: error: expected primary-expression before "targetVertex"
makefile.txt:7: recipe for target `MinPriority.o' failed
make: *** [MinPriority.o] Error 1

Basically I am trying to access a function of Graph.h (located in private:) who's purpose is to pass by reference a vector of the linked list at a given index. Basically it looks at a vector of linked lists, goes to a certain index of the vector and turns its linked list into a vector and passes it by reference to a function in another file. Here is where the error occurs.

void MinPriority::createArray()
{
    Graph::get_adjLine(vector<Edge>&, string targetVertex); //MinPriority.ccp.50: error
}

Here is the function get_adjLine() itself:

void Graph::get_adjLine(vector<Edge>& v, string targetVertex) //passes back a node and its adjacencies in the form of a vector
{
    //vector<Edge> v;
    int index;
    for(unsigned int i = 0; i != adjList.size(); i++) //find the targetVertex's index
    {
        if(adjList[i].front().m_vertex == targetVertex)
        {
            index = i;
            continue;
        }
    }
    copy(adjList[index].begin(), adjList[index].end(), v.begin());
}

I am currently trying to find any possible way to pass the private structure of vector< list<Edge> > adjList; into MinPriority::createArray(). Any way would be best for me, but i spent the last few hours trying to come up with a way to do it, but I can't figure it out. Here are the class declarations: Graph.h

#ifndef GRAPH_H_INCLUDED
#define GRAPH_H_INCLUDED
//class MinPriority;
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <locale>
using namespace std;
//class MinPriority;
class Graph
{
public:
    Graph();
    ~Graph();
    void set_Edge(string targetVertex, string vertex, int weight);
    void set_array(string vertex);
    void ABC_array();
    void print_Test();
    friend class MinPriority; //allow MinPriority to access private functions/variables
private:
    class Edge
    {
    public:
        Edge(string vertex, int weight)
        {m_vertex = vertex; m_weight = weight;}
        ~Edge(){}
        string m_vertex;
        int m_weight;
    };
    void get_adjLine(vector<Edge>&, string targetVertex);
    vector< list<Edge> > adjList;

};


#endif // GRAPH_H_INCLUDED

and MinPriority.h

#ifndef MINPRIORITY_H_INCLUDED
#define MINPRIORITY_H_INCLUDED
#include <iostream>
#include <string>
#include <vector>
#include <list>
using namespace std;
class Graph; //letting MinPriority know about Graph
class Edge; //letting MinPriority know about Graph::Edge
class MinPriority
{
    //Min heap property: A[PARENT(i)] <= A[i];
public:
    MinPriority();
    ~MinPriority();
    void createArray();
    void MIN_HEAPIFY(int);
    void BUILD_MIN_HEAP(int);
    string HEAP_MINIMUM();
    void INSERT(int);
    int HEAP_SIZE();
    int PARENT(int);
    int LEFT(int);
    int RIGHT(int);
private:
    class priority
    {
        priority(string preVertex, string vertex, int weight)
        {m_preVertex = preVertex; m_vertex = vertex; m_weight = weight;}
        ~priority(){}
        string m_preVertex;
        string m_vertex;
        int m_weight;
    };
    vector<priority> heapArray;
    vector<priority> priorityQueue;
};


#endif // MINPRIORITY_H_INCLUDED
Was it helpful?

Solution

First of all, Graph::get_adjLine is not a static member function, so you cannot call it like this:

Graph::get_adjLine(....)

You need to call it on an instance:

Graph g = ....;
g.get_adjLine(.....);

Second, you need to pass it some parameters. You seem to be using function declaration syntax in a function call:

Graph::get_adjLine(vector& adjList, string targetVertex);

should be something like

g.get_adjLine(someEdgeVector, someString);

OTHER TIPS

Are you trying to do this:

void MinPriority::createArray()
    {
        Graph::get_adjLine(vector<Edge>& adjList, string targetVertex);
    }

Actually, since adjList is a member of Graph class, you don't need to pass it as a parameter in the member function. You can use it directly instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top