473,406 Members | 2,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Problem with C++ Vector

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
Jan 16 '07 #1
0 1261

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Forecast | last post by:
I run the following code in UNIX compiled by g++ 3.3.2 successfully. : // proj2.cc: returns a dynamic vector and prints out at main~~ : // : #include <iostream> : #include <vector> : : using...
13
by: Joseph | last post by:
I was doing my assignment,but encountered a problem at last step!!!!!! for easy reading, i ommited lots of other things //=====================code begin================================...
13
by: Adam Hartshorne | last post by:
Hi All, I was wondering if anybody can tell me what is wrong with the following code, in a .h file I have std::list<std::vector<Site> > positions ; std::list<std::vector<Site> >::iterator...
3
by: rahul8143 | last post by:
hello, I write a following program and have problem in understanding constructors and destructors. #include <iostream.h> class vector { public: double x; double y;
0
by: rokuingh | last post by:
ok, so i've been working on this one for quite a while, and the code is very big so i'm just going to give the relevant parts. this is a program that builds polymers (chemical structures of repeated...
4
by: Prasad | last post by:
HI. I have written the following code..in VC++(win32 console with MFC support) CMapStringToPtr chat; vector<UserMessage *> v; /* UserMessage is a class.. */
5
by: Pradeep | last post by:
Hi All, I am facing some problem using istream_iterator for reading the contents of a file and copying it in a vector of strings.However the same thing works for a vector of integers. The...
11
by: Brian | last post by:
Dear Programmers, I have a class with a pointer to an array. In the destructor, I just freed this pointer. A problem happens if I define a reference to a vector of this kind of class. The...
8
by: Mike Jolley | last post by:
Hello First off, I'm a student so I'm pretty new to C++, and therefore I have probably made a stupid mistake somewhere. Anyway Ive been trying to fix this 5 hours straight now, so i need a...
2
by: bingo | last post by:
Hi, All: I was really new to C++, so please forgive me if I asked stupid questions. I was trying to use this following Vector class(not written by me) to do some calculations : ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.