|
-
April 10th, 2002, 05:48 PM
#1
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
-
April 10th, 2002, 06:56 PM
#2
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
-
April 10th, 2002, 06:58 PM
#3
Re: Dinamic array of structures
m_Data *m_DinamicData = new m_Data[y];
-
April 10th, 2002, 07:09 PM
#4
Re: Dinamic array of structures
nop it doesn't compile, y must be a constant value
eg: 1,2,3 etc...
-
April 10th, 2002, 08:23 PM
#5
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
-
April 10th, 2002, 09:26 PM
#6
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
-
April 11th, 2002, 12:56 PM
#7
Re: Dinamic array of structures
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|