Archived

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

AikonIV

GCC 3.2 pointer arithmmetic problem

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