Dinamic array of structures
Hi, i would like to know if there is a way I can build a dinamic array of structures.
I'v got this:
struct m_Data{
ULONG m_Size;
ULONG m_Address;
ULONG m_RawData;
ULONG m_PointerToRawData;
};
is there a way I can build an array from this struct??
I need to do something like this
m_Data *m_DinamicData[] = new m_Data[y];
where y is a value i get from another function.
The compiler expect for a constant value instead of y, and gives me an error
Tnx
Re: Dinamic array of structures
you must omit the [] symbols.
and you don't want to do that anyway because you have std::vector
The best things come to those who rate
Re: Dinamic array of structures
m_Data *m_DinamicData = new m_Data[y];
Re: Dinamic array of structures
nop it doesn't compile, y must be a constant value
eg: 1,2,3 etc...
Re: Dinamic array of structures
Are you sure you use C++ compiler?
this code:
some_type *p = new some_type[some_var];
must work - it is standard
it's same as
some_type *p = (some_type*) malloc(some_var * sizeof(some_type)); // this is C style allocation
Re: Dinamic array of structures
#include <vector>
//...
struct m_Data{
ULONG m_Size;
ULONG m_Address;
ULONG m_RawData;
ULONG m_PointerToRawData;
};
//...
// Create a dynamic array using std::vector
std::vector<m_Data> m_DynamicData(y);
//..
m_DynamicData[0].m_Size = whatever;
//...
No new, no delete, no problems.
Regards,
Paul McKenzie
Re: Dinamic array of structures