Jump to content
  • Advertisement
Sign in to follow this  
Phy

Array of Pointers

This topic is 4945 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'm trying to make an array of pointers in VC++ 7.0, but nothing I try works :X I'm using the following:
// Header file

class PointLight
{
public:
	void operator = ( const PointLight* &l );

	Vertex3f	pos;
	Vertex3f	vel;
	float		str;
	float		sqrstrrcp;
	Color4f		scol;
	Color4f		ecol;
	float		birth;
	float		death;
};

// Source file

#define MAX_POINTLIGHTS 16

// Inside Function
PointLight**    Lights;
Lights = new (PointLight*)[MAX_POINTLIGHTS];
for ( int i = 0; i < MAX_POINTLIGHTS; i++ )
    Lights = NULL;

can anyone help me out?

Share this post


Link to post
Share on other sites
Advertisement
The parentheses aren't needed because it's obvious where the type ends and the array subscript begins. With them (i.e. if there is no identifier between 'new' and the opening bracket), the compiler thinks you are asking to use "placement new" (google it if you dare), and then the rest of the line is garbage in that context.

Share this post


Link to post
Share on other sites
Funny, we were just discussing placement new yesterday...

When you present a single parameter to new as such, what you are presenting to it is a preallocated memory location to construct the object in, versus having new allocate the memory for you and construct it there.

Share this post


Link to post
Share on other sites
Odd, GCC compiles this just fine:

#define MAX_POINTLIGHTS 16

class PointLight
{
};

int main ( void )
{
PointLight ** Lights;
Lights = new (PointLight*)[MAX_POINTLIGHTS];
return 0;
}




Which makes sense, since the placement new syntax requires a value argument (read: not a typename as supplied) and then still needs a typename after it (as in: "new (...) PointLight [MAX_POINTLIGHTS];")

To the OP: please allways include error messages when possible.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!