本文介绍了解释错误:ISO C ++禁止没有类型的“Personlist”的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类,它将处理我之前创建的另一个类的对象数组(它工作正常)。

I have a class which is going to handle an array of objects of another class I've created earlier (which works fine). The problem appears when I try to create an object of my 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

这是主要功能:

#include <iostream>
#include "PersonList.h"

using namespace std;

int main() {

PersonList personlist;

return 0;
}

编译器给我的错误如下:

The error my compiler is giving me is the following:

我搜索了答案,但由于我对C ++很新,它有点混乱,我还没有找到任何适合。

I've searched for answers but as I'm quite new to C++ it's been a bit confusing and I haven't found any fitting yet. It would be great if you could explain this error for me.

推荐答案

你的构造函数声明的大小写错误。您有 Personlist(); 但需要 PersonList(); 。因为你所拥有的不等于类名,它被认为是一个函数而不是一个构造函数,而一个函数需要一个返回类型。

You have the wrong capitalisation on your constructor declaration. You have Personlist(); but need PersonList();. Because what you have isn't equal to the class name it is considered a function rather than a constructor, and a function needs a return type.

这篇关于解释错误:ISO C ++禁止没有类型的“Personlist”的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 12:42