I am new to using the standard template library. I have tried to create a struct of vector
first.h
struct help
{
uint32 a;
uint32 b;
uint32 c;
unit32 d;
}
vector <help> HelpVectoor;
In another file second.cpp
I populated value a = 12 , b = 20, c = 30, d =40 and did a push_back into the vector.
When trying to iterate though the struct in the same program the values were printed just fine.
I tried viewing the address of the a via gdb and things were appearing correctly when printing the content.
When iterated the same vector in another problem third.cpp the value of a was 13456788 and same for b. The var c and d retrained their values.
See below the value of A traced with address
std::__simple_alloc<PrefData, std::__default_alloc_template<true, 0> >::deallocate (__p=0x80b8298, __n=1) at stl_alloc.h:242
242 { if (0 != __n) _Alloc::deallocate(__p, __n * sizeof (_Tp)); }
(gdb) x 0x80b8298
0x80b8298: 0x0000000c<---- Value of A
(gdb) s
0x080546ba in std::_Vector_alloc_base<PrefData, std::allocator<PrefData>, true>::_M_deallocate (this=0xbfffdb0c, __p=0x80b8298, __n=1) at stl_vector.h:130
130 _M_deallocate(_Tp* __p, size_t __n) { _Alloc_type::deallocate(__p, __n);}
(gdb) x 0x80b8298
0x80b8298: 0x080b82a8<--------Value of A messed up.
Can anyone explain to me why a destructor gets called in this case and the value of the vector variables are not being displayed properly when accessed from a diff *.cpp file.
Your help will be highly appreciated
Regards,
Danya