Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to pass an object by reference to be used by another file
    primarykey
    data
    text
    <p>I want to access this function in a file known as MinPriority.cpp: </p> <pre><code>MinPriority::priority&amp; MinPriority::HEAP_EXTRACT_MIN(*this) //dequeue's min element of tree { MinPriority::priority&amp; min = heapArray.front(); heapArray.erase(heapArray.begin()); MIN_HEAPIFY(0); return min; } </code></pre> <p>It is supposed to dequeue an element from the vector <code>heapArray</code> and pass the object <code>priority</code> into another file known as Graph.cpp. Here is where the function is called in Graph.cpp...</p> <pre><code>void Graph::MST_PRIM() { MinPriority priority; for(unsigned int i = 0; i != adjList.size(); i++) { priority.createArray(adjList[i].front().m_vertex, *this); } while(priority.queue_Empty() == false) { priority&amp; u = priority.HEAP_EXTRACT_MIN(/*...*/); //graph.cpp 88 } } </code></pre> <p>class MinPriority is declared as: (sketched it up for simplicity)</p> <pre><code>class MinPriority { private: class priority { public: 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&lt;priority&gt; heapArray; public: //member functions are included here... }; </code></pre> <p>basically, in the end, I want to be able to pop stuff out of heapArray, pass it to functions in Graph.cpp and possibly modify things already in the heapArray from Graph.cpp. I never need push things onto the data structure as they are already there (because of a function not shown). Error:</p> <pre><code>$ make -f makefile.txt g++ -Wall -W -pedantic -g -c Graph.cpp Graph.cpp: In member function `void Graph::MST_PRIM()': Graph.cpp:88: error: `u' undeclared (first use this function) Graph.cpp:88: error: (Each undeclared identifier is reported only once for each function it appears in.) Graph.cpp:88: error: no matching function for call to `MinPriority::HEAP_EXTRACT_MIN()' MinPriority.h:39: note: candidates are: MinPriority::priority&amp; MinPriority::HEAP_EXTRACT_MIN(MinPriority::priority&amp;) Graph.cpp: At global scope: Graph.cpp:97: warning: unused parameter 'vertex' makefile.txt:9: recipe for target `Graph.o' failed make: *** [Graph.o] Error 1 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload