C++ ctor compiler mess

Started by
0 comments, last by glitchh 20 years ago
I was just porting some old project from Dev-C++ over to VisualC++ .NET and found a funny compiler problem. code snippet:

	const Dimension Dims (8,8,8);
	const int size = Dims.Width*Dims.Height;
	Layers = new Layer [Dims.Depth];
	for ( int n=0; n < Dims.Depth; n++ )
	{
        	Layers[n].Cells = new Cell [size] (session); // this works fine in gcc
    	}
  
Cell is a class that takes a 'Session*' as parameter for the constructor. There's an array of Layers, with a Layer being just a struct holding a pointer to an array of Cells. As you may guess I'm just mimicing a 3 dimensional array of Cell's, for whatever reasons (very old and messy project). Now that line inside the loop compiles just fine in gcc (and it works fine at runtime). However in VisualC++ .NET I get a "C2075: 'Target of operator new()' : array initialization needs curly braces" error. I have tried every possible way but can't get it compiled right in VC++. I have done a quick workaround hack (a setSession() method for the Cell class to work around the constructor call problem). Can anyone tell what the correct syntax is for such an initialization and which compiler actually does the right thing here? [Edit: Just don't use i as an index on GDNet. The forum interprets it as italics.] [edited by - Oluseyi on April 11, 2004 11:41:16 AM]
Advertisement
Using an initializer in an array new expression is a gcc extension. If you compiled your program with -pedantic flag in Dev C++, it would have given you an error too.

This topic is closed to new replies.

Advertisement