Advertisement Jump to content
Sign in to follow this  

error when using new operator in class

This topic is 3016 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 {
CollisionMap(const int w,const int h) {
width = w;
height = h;
*map = new boost::dynamic_bitset<>(w*h);
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:
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
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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!