このコードではnamespace stdをどうやら認識できていないようで、
NULLなども解決できないと言われてしまいました。
templateを使うときはヘッダーファイルにインターフェースと実装を二つ含めるという事でnamespace stdはどこに置くべきでしょうか?
またほかの原因でこのエラーが起きているなら、教えていただけるととても助かります。
よろしくお願いします
コード template<class ItemType> struct NodeType; template<class ItemType> class Circularlinked { public: Circularlinked(); ~Circularlinked(); bool IsFull() const; int LengthIs() const; void MakeEmpty(); void RetriveItem(ItemType &item, bool &found); void InsertItem(ItemType item); void DeleteItem(ItemType item); void ResetList(); void GetNextItem(ItemType & item); private: NodeType<ItemType>* listData; int length; NodeType<ItemType>* currentPos; }; #include<cstddef> #include<new> using namespace std; template<class ItemType> struct NodeType { ItemType info; NodeType *next; }; template<class ItemType> Circularlinked<class ItemType>::Circularlinked() { length = 0; listData = NULL; } template<class ItemType> bool Circularlinked<ItemType>::IsFull() const { NodeType<ItemType>* location; try { location = new NodeType<ItemType>; delete location; return false; } catch (bad_alloc exception) { return true; } } template<class ItemType> int Circularlinked<ItemType>::LengthIs() const { return length; } template<class ItemType> void Circularlinked<ItemType>::MakeEmpty() { NodeType<ItemType>* tempPtr; while (listData != NULL) { tempPtr = listData; listData = listData->next; delete tempPtr; } length = 0; } template<class ItemType> void Circularlinked<ItemType>::RetriveItem(ItemType& item, bool&found) { bool moreToSearch; NodeType<ItemType>* location; location = listData; found = false; moreToSearch = (location != NULL); while (moreToSearch && !found) { if (location->info < item) { location = location->next; moreToSearch = (location != NULL); } else if (item == location->info) { found = true; item = location->info; } else moreToSearch = false; } } template<class ItemType> void Circularlinked<ItemType>::InsertItem(ItemType item) { NodeType<ItemType>*newNode; NodeType<ItemType>*predLoc; NodeType<ItemType>*location; bool moreToSearch; location = listData; predLoc = NULL; moreToSearch = (location != NULL); //find insertion point while (moreToSearch) { if (location->info < item) { predLoc = location; location = location->next; moreToSearch = (location != NULL); } else moreToSearch = false; } // Prepare node for insertion newNode = new NodeType<ItemType>; newNode->info = item; //Insert node into list if (predLoc == NULL) { newNode->next = listData; listData = newNode; } else { newNode->next = location; predLoc->next = newNode; } length++; } template<class ItemType> void Circularlinked<ItemType>::DeleteItem(ItemType item) { NodeType<ItemType>* location = listData; NodeType<ItemType>* tempLocation; if (item == listData->info) { tempLocation = location; listData = listData->next; } else { while (!(item == (location->next)->info)) location = location->next; tempLocation = location->next; location->next = (location->next)->next; } delete tempLocation; length--; } template<class ItemType> void Circularlinked<ItemType>::ResetList() { currentPos = NULL; } template<class ItemType> void Circularlinked<ItemType>::GetNextItem(ItemType &item) { if (currentPos == NULL) currentPos = listData; else currentPos = currentPos->next; item = currentPos->info; }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/12/19 01:49
2015/12/19 01:53
2015/12/19 03:29
2015/12/19 03:35
2015/12/20 15:31