Я хочу получить доступ к этой функции в файле, известном как MinPriority.cpp:
MinPriority::priority& MinPriority::HEAP_EXTRACT_MIN(*this) //dequeue min element of tree
{
MinPriority::priority& min = heapArray.front();
heapArray.erase(heapArray.begin());
MIN_HEAPIFY(0);
return min;
}
Предполагается, что он должен удалить элемент из векторного heapArray
и передать priority
объекта в другой файл, известный как Graph.cpp. Вот где функция вызывается в Graph.cpp...
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& u = priority.HEAP_EXTRACT_MIN(/*...*/); //graph.cpp 88
}
}
класс MinPriority объявлен как: (набросал его для простоты)
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<priority> heapArray;
public:
//member functions are included here...
};
в основном, в конце концов, я хочу, чтобы вы могли вытащить материал из heapArray, передать его функциям в Graph.cpp и, возможно, изменить вещи, уже находящиеся в heapArray из Graph.cpp. Мне никогда не нужно вводить вещи в структуру данных, поскольку они уже существуют (из-за функции, не показанной). Ошибка:
$ 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& MinPriority::HEAP_EXTRACT_MIN(MinPriority::priority&)
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
Не уверен, что вы пытаетесь сделать с этим кодом:
MinPriority::priority& MinPriority::HEAP_EXTRACT_MIN(*this) //dequeue min element of tree
{
MinPriority::priority& min = heapArray.front();
heapArray.erase(heapArray.begin());
MIN_HEAPIFY(0);
return min;
}
Но у вас есть несколько вопросов:
Я думаю, что вы действительно хотели использовать метод обертки, чтобы вернуть фронт deque и удалить его:
MinPriority::priority MinPriority::PopFront()
{
// Copy of the front element
MinPriority::priority min = heapArray.front();
// Remove/destroy the front element
heapArray.erase(heapArray.begin());
// Return the copy
return min;
}
*this
вHEAP_EXTRACT_MIN
параметровHEAP_EXTRACT_MIN
? Это не скомпилируется.