Is possible to add empty data to a vector item ?


I have a vector that stores data from a custom structure.
Ok, depending of some value I need to store addicional data of another structure.
In example :
structureA name, age, .... have_B_data.
structureB address, phone, etc ( a lot of data).

Ok I'd can have two sincronized vectors , vecA fos structA and vecB. for strucB.

I 'd want to do:
vecA.push_back(structureA)
if not have_B_data vecB.push_back(empty data) ' zero bytes .
if have_B_data vecB.push_back(structureB)

I have the idea of to avoid the spent of memory if it isn`t needed.
Any idea to do this ?
Thanks


You do this using pointers (a null pointer when there is no data).
However, why doesn't structureA have a member of structureB in the first place?
the thing I feared.... pointers.....

if structureA has a member of structureB in the first place.... I have theese bytes used ? or not ?

I know that writting code an code and pointers I can do this. But I hoped an easy solution.
I only want to save memory use....
Thanks.
There are a number of ways to do this but it really depends on what the data is and how you want to use it. One way would be to store the index of the B record in A. A negative index could indicate that there is no associated B record.
I understand.
I know that I can have two vectors the main for A and another for B. Inside A I can have an index to vectorB.
But I'd not want to do this...
Thanks again.
Last edited on
Topic archived. No new replies allowed.