2016-08-13 13 views
-1

私は、関数が構造体であるリンクリスト内の最小のセルへのポインタを返すようにしようとしています。この関数は、型指定子がないことをエラーにしています。どんな助けもありがとうございます。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 * smallest = root; 
for (Cell * i = root; i != NULL; i = i->next) { 
    if (i->value < smallest->value) { 
     smallest = i; 
    } 
} 
return smallest; 

}

+0

CおよびC++にデュアルタグを付けることはできませんか?それは良い答えを提供するために混乱しています。 – JVApen

+0

@JVApen Cはここでは決して問題にはなりませんでした。 –

+0

編集前にタグが付けられました。 (http://stackoverflow.com/posts/38930881/revisionsを参照してください) – JVApen

答えて

0

代わりの

Cell* DoublyLinkedListPriorityQueue::getSmallestCell() 

0123でなければなりません Cellとして
DoublyLinkedListPriorityQueue::Cell* DoublyLinkedListPriorityQueue::getSmallestCell() 
(C++ 11以降)

又は

auto DoublyLinkedListPriorityQueue::getSmallestCell() -> Cell * 

DoublyLinkedListPriorityQueueのインナータイプです。

+0

ありがとうございます。 Cellのスコープを他の関数の中で内部的に使用する場合、どうして私はCellのスコープを指定する必要はありませんか? –

+0

'DoublyLinkedListPriorityQueue'のメンバメソッドで使用すると、正しいスコープになります。自由な関数の中では、 'Cell'の代わりに' DoublyLinkedListPriorityQueue :: Cell'を使う必要があります。 (そのタイプBTWを短縮する 'auto'の良いユースケースです)。 – Jarod42

関連する問題