std::vector issues...

This is a discussion on std::vector issues... within the C++ Programming forums, part of the General Programming Boards category; hi!
I'm having some problems inserting data into a std::vector.
I have a class jogador that has all the variables ...

std::vector issues...

hi!

I'm having some problems inserting data into a std::vector.
I have a class jogador that has all the variables for the players, and when i insert whose variables into the std::vector, everyone of them except for the ID are saved

I don't see the connection between the .cpp you posted and the header files?gr is a guardaRedes object, but you say your problem is with the jogador class, and based on the function calls, c1 doesn't appear to be any of the classes you've listed.

campo.cpp is where i insert my players in the field and save there data on the jogadores vector that is on the equipa.h

I posted these .cpp and the .h files because i think that the linkage between them are responsible for the fact that the ID variable from jogador.h isn't being saved inside the vector jogadores that's in equipa.h

I really don't understand why i can successfully save all the jogador data inside the vector jogadores and jogador ID (string ID) isn't saved
They all belong to the same class (class jogador) and are saved the same way.

I don't see any code where you are allocating a jogador object on the heap. You must do this in order to do what you want. And also in the destructor of the class containing the vector you must call delete on the pointers in the vector or it will leak memory.

And I wouldn't call the function that does push_back insert because it's not really inserting anything. There is another function that actually does insert into a vector although you should avoid inserting as much as possible with vectors.

I don't see any code where you are allocating a jogador object on the heap. You must do this in order to do what you want.

How do i do that?

About the destructor, are you saying that i have to one for this to work?

And I wouldn't call the function that does push_back insert because it's not really inserting anything. There is another function that actually does insert into a vector although you should avoid inserting as much as possible with vectors.

You were right, that function wasn't doing anything but if it wasn't working how were the other jogador variables getting saved on the jogadores vector?

Is there another way to insert the data i want into the vector? This is a school assignment and i need to use std::vectors

7.17 Common deﬁnitions <stddef.h>
1 The following types and macros are deﬁned in the standard header <stddef.h>. Some
are also deﬁned in other headers, as noted in their respective subclauses.
2 The types are
ptrdiff_t
which is the signed integer type of the result of subtracting two pointers;
size_t
which is the unsigned integer type of the result of the sizeof operator; and
wchar_t
which is an integer type whose range of values can represent distinct codes for all
members of the largest extended character set speciﬁed among the supported locales; the
null character shall have the code value zero.

so it could be unsigned long int or unsigned long long int or whatever.

This is from the C99 draft but I think the C++ standard specifies it in a similar manner.

>What is it for?
I made in_scope a static member because I thought I had to. In order to keep track of the number of objects in_scope needed to be created before any actual objects, and persist after they were destroyed. That's mostly what static does.

>Why do i have to use it?
You don't. I was simply trying to illustrate a point about vectors of pointed-to objects. I hope you got it.