我想讓一個函數返回一個指向鏈表中最小單元的指針,其中Cell是一個結構體。該函數給我錯誤說該函數缺少一個類型說明符。任何幫助表示讚賞。C++:無法返回指向結構的指針
.h文件中
private:
// TODO: Fill this in with the implementation of your doubly-linked list
// priority queue. You can add any fields, types, or methods that you
// wish.
struct Cell {
string value;
Cell * next;
Cell * prev;
};
int count;
Cell * root;
void clear();
Cell * getSmallestCell();
.cpp文件而不是
Cell* DoublyLinkedListPriorityQueue::getSmallestCell()
Cell * DoublyLinkedListPriorityQueue::getSmallestCell() {
Cell * smallest = root;
for (Cell * i = root; i != NULL; i = i->next) {
if (i->value < smallest->value) {
smallest = i;
}
}
return smallest;
}
你不能雙重標記C和C++嗎?這是令人困惑的,以提供一個很好的答案。 – JVApen
@Jpenpen C在這裏從來沒有問題。 –
它在你編輯之前被加了標籤。 (請參閱http://stackoverflow.com/posts/38930881/revisions) – JVApen