Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

glitchh

C++ ctor compiler mess

This topic is 5329 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!