Using new with user-defined objects : LUSENET : Steve Heller's books : One Thread

Then in the default constructor for the StockItem class, in the member initialization list you have:

m_worker(new UndatedStockItem)

where I would have expected to see (new UndatedStockItem()) to invoke the default constructor for that class. Is the 'no arguments' () syntax unnecessary when you're allocating memory via new? I guess that new just needs to know what type of variable it's being asked to allocate memory for. Is this right? And would putting the "()" in there cause an error, or is this a matter of preference?

-- Mike Mannakee (, May 09, 1999


I believe you could do it either way. However, I haven't tried it so I'm not absolutely sure.

-- Steve Heller (, May 09, 1999.

Moderation questions? read the FAQ