Original Post
I have a simple structure that that''s something like this:
When I allocate a block of these using the new operator:
the constructor for the vector gets called and I can add stuff to it no problem.
If I allocate a block of them using malloc:
then the constructor for the vector doesn''t get called.
Is there a way to auto-initialize these vectors when using stuff like this? And how would I go about doing this? The problem is in the second case, I can''t add stuff to the vector since it isn''t initialized.
typedef struct {
int a;
int b;
vector<int> coll;
} MY_STRUCT;
MY_STRUCT* pStruct = new MY_STRUCT[100];
MY_STRUCT* pStruct = (MY_STRUCT*)malloc(sizeof(MY_STRUCT) * 100);