Question

In order to get...

void MinPriority::createArray(string targetVertex, Graph & graph)
{
    vector <list <Graph::Edge> >& adjList = graph.get_adjList();
}

to work I need to pass in Graph &graph by reference from another function:

void Graph::MST_PRIM()
{
    MinPriority priority;
    for(unsigned int i = 0; i != adjList.size(); i++)
    {
        priority.createArray(adjList[i].front().m_vertex, /*...*/);
    }
}

what would i put into /*...*/ to get createArray to work? Here is a rough example of what class Graph looks like:

class Graph
{
private:
    vector< list<Edge> > adjList;
public:
    Graph();
    ~Graph();
    class Edge
    {
    public:
        Edge(string vertex, int weight)
        {
            m_vertex = vertex;
            m_weight = weight;
        }
        ~Edge(){}
        string m_vertex;
        int m_weight;
    };

    vector < list < Edge > > get_adjList(){return adjList;}
    //Other functions....

};

Please notify me if you need any more information. Basically I want to access adjList by reference and use it within createArray to make a vector out of it. (in a separate class of course)

Was it helpful?

Solution

It seems all you need is to pass in *this:

priority.createArray(adjList[i].front().m_vertex, *this);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top