STL Vector problems

I've been messing with some vectors (the STL ones). In some other project I couldn't pass the vector of object types memeory adress around? Anyways why doesn't this code work?

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
//DEFAULT
#include <iostream>
#include <vector>
#include <thread>


using namespace std;

//CLASS BEGIN
class chickens
{
public:
	chickens();

	void set_chicken_size(int);

	int get_chicken_size();

	~chickens();

private:
	int chicken_size;
};

chickens::chickens()
{
}

void chickens::set_chicken_size(int set_size)
{
	this->chicken_size = set_size;
}

int chickens::get_chicken_size()
{
	return this->chicken_size;
}

chickens::~chickens()
{
}
//CLASS END

//PROTOTYPE
void change_vectors(vector<chickens>*);

int main() {

	vector<chickens> chicken_vector; //This is not an object, but a vector that takes the object type chicken

	thread change_chickens_thread(&chicken_vector); //Testing pointer with thread (not that it should matter)

	change_chickens_thread.join();//Sync

	for (int i = 0; i < 5; i++) { //Output every vector element
		std::cout << chicken_vector[i].get_chicken_size() << std::endl;
	}

	system("pause");
	return 0;
}

void change_vectors(vector<chickens> *chicken_vector_ptr) {
	chickens chicken[5]; //Create 5 chicken objects
	for (int i = 0; i < 5; i++) {//Loop for assigning chicken sizes and then assigning those objects to the back of the vector
		chicken[i].set_chicken_size(i);
		chicken_vector_ptr->push_back(chicken[i]);//Vectors are dynamically sized right?
	}
}
Last edited on
What are you trying to do on line 51? I'm surprised that even compiles.
I should go to bed... I'd agree that its pretty amazing that it even compiles when attempting to create a thread with a vector adress as function... My bad.
Last edited on
Topic archived. No new replies allowed.