-2
$ 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
user3040019
  • 51
  • 2
  • 10
  • 2
    Given your last few questions, it seems you are trying to write some relatively complex code without understanding some of the basics of the C++ language. It may be more productive to take a step back, and spend some time learning these and exercising them on simpler code. See this [list of good books](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – juanchopanza Dec 20 '13 at 10:34

2 Answers2

1

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);
BenMorel
  • 34,448
  • 50
  • 182
  • 322
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
  • I can't just start reading a textbook and teaching myself this, the assignment was assigned a week ago and I have been working on it non-stop never since. My teacher doesnt even teach us some of these subjects, she just expects us to know them already. I tried doing this: (still doesnt work at all of course) 'Graph g; vector adjLine; g.get_adjLine( adjLine& , targetVertex);' – user3040019 Dec 20 '13 at 10:50
  • Ive been working on this single subject for about 7 hours, once I get it done I should be able to finish the entire program in one sitting. – user3040019 Dec 20 '13 at 10:54
0

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.

Hariprasad
  • 3,556
  • 2
  • 24
  • 40
  • how could I use it directly? I tried doing it before and it would never see adjList – user3040019 Dec 20 '13 at 10:26
  • Doesn't matter. C++ is not a interpreted programming language. It;s just that `get_adJline()` should be defined after the `Graph` definition – Hariprasad Dec 20 '13 at 10:32