Why is there "Type undefined reference to `People::humans'"?

I am working on eclipse workspace and I have this code. I ran it into another program and it works perfectly, but eclipse doesn't like the line. Why is that, and how can I fix it?

Here is the code where the error is in (it's on line 32):

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
#include "Human.h"
#include "People.h"
using namespace std;


People::People() {
	 size = 0; position = 0;
}

People::People(int s, int p) {
	size=s;
	position=p;
}

void People::setSize(int s) {
	size = s;
}

void People::setPosition(int p) {
	position = p;
}

int People::getSize() {
	return size;
}

int People::getPosition() {
	return position;
}

void People::insert(Human h) {
	humans[position] = h;
	position++;
}


And this is People.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef SRC_PEOPLE_H_
#define SRC_PEOPLE_H_
#include "Human.h"



class People {
	private:
		int size;
		int position;
		static Human humans[100]; 
	public:
		People();
		People(int size, int position);
		void setHumans(Human humans[]);
		void setSize(int size);
		void setPosition(int position);
		Human getHumans();
		int getSize();
		int getPosition();
		Human search(std::string search);
		void insert(Human newHuman)
};
Last edited on
A static member variable needs to be defined. Add

Human People::humans[100];

to People.cpp
Also note that
void setHumans(Human humans[]);
is going to clash with
static Human humans[100];
Topic archived. No new replies allowed.