Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain the error: ISO C++ forbids declaration of `Personlist' with no type

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.

This is the header of the 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

This is the main function:

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

using namespace std;

int main() {

PersonList personlist;

return 0;   
}

The error my compiler is giving me is the following:

error: "27 \PersonList.h ISO C++ forbids declaration of `Personlist' with no type"

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.

like image 465
Ms01 Avatar asked Dec 13 '22 08:12

Ms01


1 Answers

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.

like image 162
RobH Avatar answered May 13 '23 17:05

RobH