GCC 3.2 pointer arithmmetic problem

Started by
4 comments, last by AikonIV 21 years, 1 month ago
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?
Advertisement
how about type casting your pointer?

The nightmare travels across the cosmos with his burning mane. The trail of ash that is produced.

?Have a nice day!?

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.
--God has paid us the intolerable compliment of loving us, in the deepest, most tragic, most inexorable sense.- C.S. Lewis
Try using &vector.front() instead.
That''s an idea Osc. I''ll try that.

antareus, the function is supposed to find the ID of the pointer in the vector.
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.

This topic is closed to new replies.

Advertisement