我正在返回指向一個類內聲明的結構的指針的代碼的一些問題。這是我到目前爲止的代碼:函數返回指針結構
SortedList.h
#ifndef SORTEDLIST_H
#define SORTEDLIST_H
class SortedList{
public:
SortedList();
...
private:
struct Listnode {
Student *student;
Listnode *next;
};
static Listnode *copyList (Listnode *L);
};
#endif
SortedList.cpp
#include "SortedList.h"
...
// Here is where the problem lies
Listnode SortedList::*copyList(Listnode *L)
{
return 0; // for NULL
}
顯然,複製列表方法不會編譯。我正在使用Microsoft Visual Studio,並且編譯器告訴我「Listnode」未識別。當我嘗試編譯,這裏是whhat我得到:
1>------ Build started: Project: Program3, Configuration: Debug Win32 ------
1> SortedList.cpp
sortedlist.cpp(159):錯誤C2657:「排序列表:: *」在聲明的開頭找到(你忘了指定類型?)
sortedlist.cpp(159):錯誤C4430:缺少類型說明符 - int假定。注意:C++不支持默認int
sortedlist.cpp(159):錯誤C2065:L':未聲明的標識符
sortedlist.cpp(159):錯誤C4430:缺少類型說明 - 假定爲int。注意:C++不支持default-int
sortedlist.cpp(159):致命錯誤C1903:無法從先前的錯誤中恢復;正在停止編譯
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
幫助將不勝感激......儘快
你應該使用的格式是Markdown:http://daringfireball.net/projects/markdown/basics – jogojapan