[英]Function returning pointer to struct
我在返回指向在類中聲明的結構的指針的代碼有一些問題。 到目前為止,這是我的代碼:
排序列表.h
#ifndef SORTEDLIST_H
#define SORTEDLIST_H
class SortedList{
public:
SortedList();
...
private:
struct Listnode {
Student *student;
Listnode *next;
};
static Listnode *copyList (Listnode *L);
};
#endif
排序列表.cpp
#include "SortedList.h"
...
// Here is where the problem lies
Listnode SortedList::*copyList(Listnode *L)
{
return 0; // for NULL
}
顯然,復制列表方法不會編譯。 我正在使用 Microsoft Visual Studio 並且編譯器告訴我“Listnode”未識別。 當我嘗試編譯時,這是我得到的:
1>------ Build started: Project: Program3, Configuration: Debug Win32 ------
1> SortedList.cpp
sortedlist.cpp(159):錯誤 C2657:在語句開頭找到“SortedList::*”(您是否忘記指定類型?)
sortedlist.cpp(159):錯誤 C4430:缺少類型說明符 - 假設為 int。 注意:C++ 不支持 default-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 ==========
幫助將不勝感激...盡快
在 cpp 文件中,該函數應定義為:
SortedList::Listnode* SortedList::copyList(ListNode* L)
{
return 0; //For NULL
}
此外, struct Listnode
應聲明為public
或在class SortedList
之外聲明。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.