$ 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