error: reference to non-static member function must be called

How would I go about to fix this error? The error occurs at line 60 with the message "error: reference to non-static member function must be called; did you mean to call it with no arguments?".

...
Last edited on
waranthem wrote:
How would I go about to fix this error? The error occurs at line 60 with the message "error: reference to non-static member function must be called; did you mean to call it with no arguments?".

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdlib.h>
#include <string>
#include <iostream>
#include <vector>

using namespace std;

class Person
{
    protected:
        string name;
        int ID;
        string gender;
    public:
        Person(string name, int ID, string gender)
        {
            this-> name = name;
            this-> ID = ID;
            this-> gender = gender;
        }

        const string getName () const
        {
            return name;
        }

        const int getID () const
        {
            return ID;
        }

        const string getGender () const
        {
            return gender;
        }

        vector <string> children;
};

class Male: public Person
{
    private:
        vector <Person> wife;
};


class Female: public Person
{
    private:
        vector <Person> husband;
};

void displayAll (Person *arr[])
{
    int SIZE = 10;

    cout  << "\nThe people in the system are...\n";
    for(int i = 0; i < SIZE; i++)
    {
        cout << arr[i] -> getName << "\n";    //where error occurs
    }
    cout << "\n";
}

int main()
{

    const int SIZE = 10;
    Person *arr[SIZE];

    arr [0] = new Person ("Abraham", 1, "M");
    arr [1] = new Person ("Sarah", 2, "F");
    arr [2] = new Person ("Keturah", 3, "F");
    arr [3] = new Person ("Hager", 4, "F");
    arr [4] = new Person ("Issac", 5, "M") ;
    arr [5] = new Person ("Jokshan", 6, "M");
    arr [6] = new Person ("Midian", 7, "M");
    arr [7] = new Person ("Ishmael", 8, "M");
    arr [8] = new Person ("Rebekah", 9, "F");
    arr [9] = new Person ("Esau", 10, "M");

    displayAll(arr);

    return 0;
}


1
2
3
4
5
6
7
8
9
#include <iostream>
#include <vector>

int main() {
  std::vector<int> foo;
  std::cout << foo.size() << '\n';
  std::cout << foo.size << '\n';
  return 0;
}

A different compiler says on line 7:
invalid use of non-static member function


What is wrong on my line 7 and on your line 60?
In other words, what is the proper syntax of a function call?
Last edited on
Got it! Thanks for the help keskiverto. I can't believe I overlooked such a simple thing.
Please STOP deleting your questions after you've got an answer. It ruins the thread as a learning resource for others.

(see also http://www.cplusplus.com/forum/beginner/180202/ )
Last edited on
Topic archived. No new replies allowed.