Why does the push back of pushback of vector of structs work?

So, i have a function like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void level::wall(int height, int widt, int x, int y, int z)
{
vexlog vpasser;
surlog spasser;

vpasser.x = x;
vpasser.y = y;
vpasser.z = z;

vexlogger.push_back(vpasser);
std::cout<< vexlogger[1].x<<endl;//the second line of of output comes from here
std::cout<<vpasser.x<<endl;// the last line of out put come from here

}


in a class like this:

1
2
3
4
5
6
7
8
9
10
class level{
private:
	struct cordnit{int x; int y; int z;};
	struct vexlog{int x; int y; int z; cordnit c1; cordnit c2; cordnit c3;};
	std::vector <vexlog> vexlogger;
	struct surlog{cordnit tl;cordnit tr;cordnit bl; cordnit br;};
	std::vector <surlog> surlogger;
public:
	void wall(int, int, int, int, int);
};

with main function like this:

1
2
3
4
5
6
int main() {
	cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
	level level1;
	level1.wall(10,10,20,30,0);
	return 0;
}



the output is like this:

!!!Hello World!!!
0
20


the hello would come from main, and the 0 and 20 come from the wall function


shouldnt the output be:


!!!Hello World!!!
20
20


?

Thanks
Last edited on
Note that vexlogger contains a single element at that point, and that arrays and vectors start at index 0.
Oh, ya, i forgot that! cant believe I forgot something so simple!

Thank you!
-blueberry
Topic archived. No new replies allowed.