Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Quasar

Placement new?

Recommended Posts

I was trying to code a temporary workaround for the fact that sectors, linedefs, and polyobjects need to contain an instance of CPointThinker (the class previously known as degenmobj_t), but those objects are not themselves constructed currently.

The best way to do this seemed to be with placement new; for example:

for(i = 0; i < numPolyObjects; ++i)
  new (&(PolyObjects[i].spawnSpot)) CPointThinker;
Without :: in front of the new, Visual C++ complains that CZoneLevelItem (the ultimate base class of thinkers currently)'s new operator does not accept two parameters.

WITH :: in front of new, Visual C++ complains that the global new function does not accept two parameters.

So wtf, where's my placement new??

Share this post


Link to post

I'm no expert, but does it help to do:

#include <new>

for(i = 0; i < numPolyObjects; ++i)
  new (&(PolyObjects[i].spawnSpot)) CPointThinker();
- Changed CPointThinker to CPointThinker()

Share this post


Link to post
Ladna said:

I'm no expert, but does it help to do:

#include <new>

for(i = 0; i < numPolyObjects; ++i)
  new (&(PolyObjects[i].spawnSpot)) CPointThinker();
- Changed CPointThinker to CPointThinker()

I can't test right now, but I wouldn't expect the () to make a difference given the syntax. However #include <new> may or may not make a difference - I just got the impression from what I read online that it's not supposed to be required for using placement new. I'll try it when I get home unless a more authoritative answer appears before then ;)

EDIT: Yep, #include <new> is the key. Confirmed with cplusplus.com (I should have checked there first huh ;) after testing it in the compiler.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×