I am trying to dynamically allocate storage for an array of structures, in the constructor. I am new to C++, and have tried all sorts of syntax variations, but now I am wondering whether this can be done at all.
struct Trade
{
int index;
}
define MAX_TRADES 5000
struct foo
{
Trade *trade [MAX_TRADES];
int cumeTradeCount;
foo() :
cumeTradeCount(0),
{
// here is where I want to allocate storage for cumeTradeCount Trade structures
....
memset(trade, 0, cumeTradeCount * sizeof(Trade*));
}
}
Specifically, what I am trying to figure out is how I can allocate storage for 'cumeTradeCount' structures, in the constructor. If I were doing this in C, I would do the following:
for (int i = 0; i < cumeTradeCount; ++i)
trade[i] = calloc(1, sizeof(Trade *));