我有一個稱爲OrderedList的名稱空間MYLIB中的類。其中我有一個名爲迭代器的嵌套類,它將用作OrderedList類的迭代器。C++:創建一個迭代器嵌套類的實例
下面是我創建OrderedList和迭代器類的我的代碼片段:
template<class T>
class OrderedList
{
private:
ListNode<T>* head;
ListNode<T>* tail;
int total;
public:
OrderedList(T[],int);
~OrderedList();
void insert(const T&);
void sort(int);
void output();
class iterator
{
private:
ListNode<T>* curr;
int current;
OrderedList& order;
public:
iterator(OrderedList& ord, bool is_end)
{
this->order = ord; //problem is here
if(is_end == false)
{...
摘錄我的主要功能:
int main()
{
int one[5] = {9,7,5,4,1};
MYLIB::OrderedList<int> odd(one,5);
odd.output();
MYLIB::OrderedList<int>::iterator starter(odd,false);
當我編譯它給了我下面的錯誤:
OrderedList.cpp: In instantiation of ‘MYLIB::OrderedList<T>::iterator::iterator(MYLIB::OrderedList<T>&, bool) [with T = int]’:
OrderedList.cpp:215:53: required from here
OrderedList.cpp:47:6: error: uninitialized reference member ‘MYLIB::OrderedList<int>::iterator::order’ [-fpermissive]
iterator(OrderedList& ord, bool is_end)
^
請粘貼代碼(文本)而不是圖片。 –
每次發佈代碼圖片時,都會有一隻小貓死亡。請*請*不要那樣做。 – WhozCraig
哈哈@WhozCraig。我相信發佈的圖片比文本更清晰,因爲您可以參考行號:) –