我正在開發中,我已經使用了一些受保護的變量count
,entry[maxlist]
等繼承清單排序列表保護構件超出範圍
List.h
class List
{
public:
//etc etc
protected:
int count;
int entry[maxlist];
};
Sortable_list列表.h
typedef Key Record;
class Sortable_list:public List<Record>
{
void selection_sort()
{
for(int position=count-1;position>0;i--) // Count is not declared in the scope
{
int max=max_key(0, position);
swap(max, position);
}
}
};
有什麼問題wi繼承列表到可排序列表?爲什麼它顯示超出範圍?
你繼承權列表?您的List.h不是模板類,而是從列表繼承... –
2011-01-11 13:28:45
它實際上是一個模板。我剛剛在上面寫了手寫。以下是List.h的完整代碼:pastebin.com/3xTADqvN這裏有什麼問題嗎? – Cipher 2011-01-11 14:21:53
我測試了你的代碼,除了``using namespace std``和使用'i`而不是``````在`for`循環中使用的一些問題,你的代碼會被編譯。你確定你在`Sortable_list.h`中包含了`List.h`嗎? – 2011-01-11 15:01:57