[英]Function returning pointer to struct
I am having some issues with code that is returning a pointer to a struct declared inside a class.我在返回指向在类中声明的结构的指针的代码有一些问题。 Here is my code so far:到目前为止,这是我的代码:
SortedList.h排序列表.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排序列表.cpp
#include "SortedList.h"
...
// Here is where the problem lies
Listnode SortedList::*copyList(Listnode *L)
{
return 0; // for NULL
}
Apparently, the copy list method wont compile.显然,复制列表方法不会编译。 I am using Microsoft Visual Studio and the compiler tells me that "Listnode" is unidentified.我正在使用 Microsoft Visual Studio 并且编译器告诉我“Listnode”未识别。 When I try to compile, here is whhat I get:当我尝试编译时,这是我得到的:
1>------ Build started: Project: Program3, Configuration: Debug Win32 ------
1> SortedList.cpp
sortedlist.cpp(159): error C2657: 'SortedList::*' found at the start of a statement (did you forget to specify a type?) sortedlist.cpp(159):错误 C2657:在语句开头找到“SortedList::*”(您是否忘记指定类型?)
sortedlist.cpp(159): error C4430: missing type specifier - int assumed. sortedlist.cpp(159):错误 C4430:缺少类型说明符 - 假设为 int。 Note: C++ does not support default-int注意:C++ 不支持 default-int
sortedlist.cpp(159): error C2065: 'L' : undeclared identifier sortedlist.cpp(159):错误 C2065:“L”:未声明的标识符
sortedlist.cpp(159): error C4430: missing type specifier - int assumed. sortedlist.cpp(159):错误 C4430:缺少类型说明符 - 假设为 int。 Note: C++ does not support default-int注意:C++ 不支持 default-int
sortedlist.cpp(159): fatal error C1903: unable to recover from previous error(s); sortedlist.cpp(159):致命错误 C1903:无法从之前的错误中恢复; stopping compilation停止编译
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Help would be greatly appreciated...ASAP帮助将不胜感激...尽快
Inside the cpp file, the function should be defined as:在 cpp 文件中,该函数应定义为:
SortedList::Listnode* SortedList::copyList(ListNode* L)
{
return 0; //For NULL
}
Also, the struct Listnode
should be declared either public
or outside the class SortedList
.此外, struct Listnode
应声明为public
或在class SortedList
之外声明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.