Jump to content
  • Advertisement

Archived

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

AikonIV

GCC 3.2 pointer arithmmetic problem

This topic is 5585 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 just switched to GCC 3.2 yesterday, and now I have an interesting problem while trying to do some pointer arithmetic that worked fine in the old version (2.9.5.something). I have a function that you pass a pointer to an object that is in a std vector containing a bunch of classes. The function takes that pointer, subtracts vector.begin() from it. Except, GCC now thinks that I am trying to use an overloaded operator of the class instead of standard arithmetic. Anyone know how to get around this?

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by AikonIV
I just switched to GCC 3.2 yesterday, and now I have an interesting problem while trying to do some pointer arithmetic that worked fine in the old version (2.9.5.something).

I have a function that you pass a pointer to an object that is in a std vector containing a bunch of classes. The function takes that pointer, subtracts vector.begin() from it. Except, GCC now thinks that I am trying to use an overloaded operator of the class instead of standard arithmetic. Anyone know how to get around this?

Why do you do pointer arithmetic in the first place? Just pass around an index into the vector.

Share this post


Link to post
Share on other sites
That''s an idea Osc. I''ll try that.

antareus, the function is supposed to find the ID of the pointer in the vector.

Share this post


Link to post
Share on other sites
To get the behavior you need, use &vector[0] or use .font() as suggested. Your code is not working anymore because you assume that obj.begin(), which returns an iterator, returns a pointer. That was true in earlier version of GCC, but the new stl that they are using now has a specific object for an iterator.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!