Error LNK2001 unresolved external symbol "private: static class

Ive been trying to understand how to resolve this issue and I just cant wrap my head around it. Notes: Creating bunny objects so they have a name,age,gender,color,and uuid. class Bunnys is for storing all bunnys created. This is also very unfinished as I had this error popup

Error:
1
2
1>bunnys.obj : error LNK2001: unresolved external symbol "private: static class std::vector<class Bunny,class std::allocator<class Bunny> > Bunnys::bunnys_list" (?bunnys_list@Bunnys@@0V?$vector@VBunny@@V?$allocator@VBunny@@@std@@@std@@A)
1>uuid.obj : error LNK2001: unresolved external symbol "private: static class std::vector<class Uuid,class std::allocator<class Uuid> > Uuid::uuid_list" (?uuid_list@Uuid@@0V?$vector@VUuid@@V?$allocator@VUuid@@@std@@@std@@A)


uuid.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef UUID_H
#define UUID_H

class Uuid {
private:
	static std::vector <Uuid> uuid_list;

	int uuid;

	static void addUuid(Uuid uuid);

public:
	// Uuid able to convert to int //
	operator int() { return this->uuid; }

	Uuid(int uuid) : uuid(uuid) {}
	////////////////////////////////

	static Uuid Generate();
};

#endif 


uuid.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <vector>

#include "Uuid.h"

// public
Uuid Uuid::Generate() {
	int uuid;

	if (uuid_list.size() == 0) {
		uuid = 0;
	}

	else {
		uuid = uuid_list.back() + 1;
	}

	Uuid::addUuid(uuid);
	return uuid;
}

void Uuid::addUuid(Uuid uuid) {
	uuid_list.push_back(uuid);
}


bunnys.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "bunny.h"

#ifndef BUNNYS_H
#define BUNNYS_H

class Bunnys {
private:
	static std::vector<Bunny> bunnys_list;

public:
	// Initilize
	Bunnys(std::vector <Bunny> bunnys);

	static void addBunny(Bunny bunny);

	static void removeBunny(Bunny bunny);
};

#endif 


bunnys.cpp
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
#include <string>
#include <vector>

#include "bunnys.h"

static std::vector<Bunny> bunnys_list;

// public
Bunnys::Bunnys(std::vector <Bunny> bunnys) {
	bunnys_list = bunnys;
}

void Bunnys::addBunny(Bunny bunny) {
	bunnys_list.push_back(bunny);
}

void Bunnys::removeBunny(Bunny bunny) {
	int index = NULL;

	for (int i = 0; i < bunnys_list.size(); i++) {
		if (bunnys_list[i].getUuid() == bunny.getUuid()) {
			index = i;
		}
	}

	if (index != NULL) {
		bunnys_list.erase(bunnys_list.begin() + index);
	}
}
Last edited on
Line 6 should be:

static std::vector<Bunny> Bunnys::bunnys_list;

and similar for uuid_list
Last edited on
1
2
3
4
5
// Add this to uuid.cpp
std::vector<Uuid> Uuid::uuid_list;

// Add this to bunnys.cpp
std::vector<Bunny> Bunnys::bunnys_list;

It looks like you tried to do the latter but didn't do it quite right.
// Add this to uuid.cpp
std::vector<Uuid> Uuid::uuid_list;

// Add this to bunnys.cpp
std::vector<Bunny> Bunnys::bunnys_list;

It looks like you tried to do the latter but didn't do it quite right.


Oh, I did something like this but I wasnt adding the Class to the object. Thank you
Topic archived. No new replies allowed.