Jump to content
  • Advertisement
Sign in to follow this  
paul23

error when using new operator in class

This topic is 2833 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

Well it's hard to describe the problem, as I'm surprised it IS a problem (I really thought it was perfectly fine code):

The code I use (I stripped everything untill the most basic):
class CollisionMap {
public:
CollisionMap(const int w,const int h) {
width = w;
height = h;
*map = new boost::dynamic_bitset<>(w*h);
}
private:
boost::dynamic_bitset<>* map;
unsigned int width;
unsigned int height;
};


I'm using a pointer/new structure as I heard (is this correct?) that for large amounts of data it is better to use the heap instead of the stack.

When compiling this gives the error:
Quote:
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'boost::dynamic_bitset<> *' (or there is no acceptable conversion)

what am I doing wrong (and how should I do it)?

Share this post


Link to post
Share on other sites
Advertisement
new boost::dynamic_bitset<>(w*h); returns a pointer to a dyanmic_bitset. Your map variable is a pointer to a dynamic_bitset. You don't need to dereference map in order to assign the pointer.

Share this post


Link to post
Share on other sites
dynamic_bitset probably does a heap allocation internally for you. You don't need to dynamically allocate the dynamic_bitset, you are just adding an additional and unnecessary level of indirection, which also complicates the rest of your code (such as requiring destructors and possibly copy implementations).

You should use the heap for large amounts of data. On Windows the stack defaults to about 1 Megabyte, excessive stack allocations can cause a stack overflow error. It also limits the depth of recursion.

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!