why doesnt this memory allocation work ?

Started by
2 comments, last by djsteffey 22 years, 5 months ago
  
CProcessControlBlock**	currentProcessOnDevice;
currentProcessOnDevice = new (CProcessControlBlock*)[args->numDevices];
  
error is C:\Documents and Settings\Administrator\My Documents\classes\csc246\program3\CSimulatedOS.cpp(27) : error C2143: syntax error : missing '';'' before ''['' this is for a class but it isnt like i am asking you how to program stuff. now that i think about it i dont believe i have ever got dynamic 2d arrays to work in MSVC 6.0 what this is doing is creating an array of pointers. it does know what type CProcessControlBlock is because I am including the header for that class and it would say unndefined type or something if it didnt know the type. "I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma." - Mr. T
Advertisement
Probably the paranthesis are confusing the compiler. It might think you''re trying to use placement new. Try leaving them out. e.g.

currentProcessOnDevice = new CProcessControlBlock*[args->numDevices];

-Mike
-Mike
  CProcessControlBlock**	currentProcessOnDevice;currentProcessOnDevice = new CProcessControlBlock*[args->Devices];  

Dunno why really...maybe the compiler parses it as a cast?

Although...
  vector< vector< CProcessOnDevice > > currentProcessOnDevice;  

_might_ be preferrable.



"I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours." - - Stephen Roberts
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
thanks guys. I left off the parenthesis and it worked.

"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T

This topic is closed to new replies.

Advertisement