Ms0*_*s01 4 c++ compiler-errors
我有一个类,它将处理我之前创建的另一个类的对象数组(工作正常).当我尝试创建List-class的对象时出现问题.
这是list-class的标题:
#ifndef personlistH
#define personlistH
#include "Person.h"
#include <iomanip>
#include <iostream>
#define SIZE 10
namespace std {
class PersonList {
private:
Person persons[SIZE];
int arrnum;
string filename;
public:
Personlist();
};
}
#endif
Run Code Online (Sandbox Code Playgroud)
这是主要功能:
#include <iostream>
#include "PersonList.h"
using namespace std;
int main() {
PersonList personlist;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的编译器给出的错误如下:
错误:"27\PersonList.h ISO C++禁止声明`Personlist'没有类型"
我已经搜索了答案,但由于我对C++很陌生,所以有点令人困惑,我还没有找到合适的答案.如果你能为我解释这个错误会很棒.
您的构造函数声明上的大小写错误.你有Personlist();但需要PersonList();.因为你拥有的不等于类名,所以它被认为是函数而不是构造函数,函数需要返回类型.