[英]Implementing a template Linked List class using arrow (->)
我在實現模板鏈接列表類時遇到問題。 我之前做了鏈接列表,但沒有作為模板。
在.cpp文件(實現)中,似乎無法將成員指針變量識別為成員,並且在這些指針不起作用后使用->
。 問題附近沒有語法錯誤的下划線,但是當我突出顯示該變量時,說明說“未知”,並且該變量的詳細信息
(甚至更奇怪的是,我放在示波器中的任何東西都無法獲得下划線語法錯誤。)
// ListLinked.h
#include <iostream>
using namespace std;
template <typename DataType>
class List {
private:
struct ListNode {
DataType dataItem;
ListNode* next;
};
ListNode* head;
ListNode* cursor;
public:
List(int ignored = 0);
List(const List& other);
List& operator=(const List& other);
~List();
void insert(const DataType& newDataItem);
void remove();
void replace(const DataType& newDataItem);
void clear();
bool isEmpty() const;
bool isFull() const;
void gotoBeginning();
void gotoEnd();
bool gotoNext();
bool gotoPrior();
void showStructure() const;
DataType getCursor() const;
};
//ListLinked.cpp (just the simplest one of the many member functions that use ->)
template <typename DataType>
bool List<DataType>::gotoNext(){
if (cursor->next != NULL) //"next" is not seen as a member pointer variable
cursor = cursor->next;
}
// all the other member functions start with
// template <typename DataType>
// [type] List<DataType>:: {...}
我懷疑視覺表達2010出了點問題,但我不確定
使用模板化的類/函數時,需要在源文件中包含整個實現。 首先將所有模板引用都放在.h文件中;)
如果您想在不使用功能代碼的情況下保持標題的整潔,可以創建一個名為linkedlist.impl
的文件並放入您的定義中。 在標題的末尾,在您的警惕之前,添加#include "linkedlist.impl"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.