Recommended Posts

The code below contains some classes (functor stuff, then two object classes just being used as examples). Below the classes, the code creates two functors using slightly different methods, both of which *should* work. Without the /O2 flag set, the code runs fine... it displays two message boxes, one saying HI!, then the next saying Hello. as it should. However, if the flag is set, both boxes display HI!. Also, if the first functor isn't created, the second one throws an exception - read the comments:

Anyone know what's going on? Tracking the problem down to this took me forever, and now that I've found it, I have no idea how to fix it .
[EDIT]
Added a little bit of description to the introduction to make it easier to understand what's going on...
And here are a few more things I've figured out while playing with the code:
My first thought had been that no memory was being allocated for the second functor, and it somehow ended up pointing at the first functor for some reason... but I tried adding some data to both classes, and when accessing that data through the functors (I made the obj members public to do this), it seems fine, so that's not it...
[edited by - HappyDude on April 10, 2004 11:38:09 PM]

0

Share this post

Link to post

Share on other sites

Upon further messing around with the code, I've discovered that the functor pointers are actually pointing to exactly the same memory location (but only with /O2 set)... however, for reasons unknown, the data members within the object that the functors are pointing to are distinct (and are the way they should be). This makes no sense to me, because since both pointers are pointing to the same memory location, all of the data members accessed through the pointers should be exactly the same...