Invalid use of non-static data member
<p>I want to create a file in which I can add Persons to a PersonList including a counter that makes sure that the capacity of the PersonList is not exceeded. I commented all the functions to make clear what task(s) they should perform.</p>

<p>During compilation I get the following error:</p>

<pre><code>invalid use of non-static data member 'PersonList::m_Capacity'
</code></pre>

<p>Unfortunately I cannot figure out what's wrong in the code:</p>

<p>main.cpp</p>

<pre><code>#include &lt;iostream&gt;
#include "Person.h"
#include "PersonList.h"

int main()
{

    Person p1 = Person("John", 21);
    Person p2 = Person("Elham", 19);
    PersonList p_list = PersonList();

    p_list.add(p1);
    p_list.add(p2);

    std::cout &lt;&lt; p_list.get_Size() &lt;&lt; std::endl;
    Person p = p_list.get(0);
    std::cout &lt;&lt; p.get_Name() &lt;&lt; " " &lt;&lt; p.get_Age() &lt;&lt; std::endl;

    return 0;
}
</code></pre>

<p>Person.h</p>

<pre><code>#ifndef PERSON_H
#define PERSON_H

class Person
{
    public:
        Person();
        Person(std::string Name, int Age);

        void set_Name(std::string name);
        void set_Age(int age);
        std::string get_Name();
        int get_Age();

    private:
        std::string m_Name;
        int m_Age;
};

#endif // PERSON_H
</code></pre>

<p>Person.cpp</p>

<pre><code>#include &lt;string&gt;
#include "Person.h"

Person::Person(){}

Person::Person(std::string Name, int Age){
// pre:  0 &lt;= Age
// post: m_Name, if pre Name (is true) Age = m_Age,
//       otherwise age = -1

    set_Name(Name);

    if (0 &lt;= Age){

        set_Age(Age);
    }

    else{

        set_Age(-1);
    }

}

void Person::set_Name(std::string Name){
// post: m_Name = Name

    m_Name = Name;
}

void Person::set_Age(int Age){
// pre:  0 &lt;= Age
// post: if pre Age (is true) = m_Age, otherwise m_Age = -1;

    if (0 &lt;= Age){

        m_Age = Age;
    }

    else set_Age(-1);
}

std::string Person::get_Name(){
// post: returns name

    return m_Name;
}

int Person::get_Age(){
// post: returns age

    return m_Age;
}
</code></pre>

<p>PersonList.h</p>

<pre><code>#ifndef PERSONLIST_H
#define PERSONLIST_H

class PersonList
{
    public:
        PersonList();

        void add(Person p);
        void set_Size(int Size);
        int get(int index);
        int get_Size();

    private:
        const int m_Capacity;
        const Person m_Empty;
        Person m_Data[m_Capacity];
        int m_Size;

};

#endif // PERSONLIST_H
</code></pre>

<p>PersonList.cpp</p>

<pre><code>#include "Person.h"
#include "PersonList.h"

PersonList::PersonList()
m_Capacity(10), m_Empty(Person())
{
// post: has created a new PersonList-object with
//      CAPACITY elements and size = 0

    set_Size(0);
}

void PersonList::add(Person p){
// pre:  size &lt; CAPACITY
// post: if pre (is true) p has been stored at the
//      first empty location. size was incremented.

    if (m_Size &lt; m_Capacity){

        m_Data[m_Size] = p;
        set_Size(m_Size+1);
    }

}

void set_Size(int Size){

    m_Size = Size;
}

int PersonList::get(int index){
// pre:  0 &lt;= index &amp;&amp; index &lt; size
// post: if pre returns data[index] otherwise returns EMPTY

    if (0 &lt;= index &amp;&amp; index &lt; m_Size){

        return m_Data[index];
    }

    else{

        return m_EMPTY;
    }
}

int PersonList::get_Size(){
// post returns size;

    return m_Size;

}
</code></pre>
