gcc is being very annoying in regards to passing by reference.
Apparently the following snippet of code doesn't work (just look at the last CRect parameter passed to the constructor):
Testing::CPhysicsTickerObserver *view = new
Testing::CPhysicsTickerObserver(model, g, g.get_font_small(),
CColor(10), CRect(0, 0, 100, 100));
To make things work, I have to change it to:
CRect rect(0, 0, 100, 100);
Testing::CPhysicsTickerObserver *view = new
Testing::CPhysicsTickerObserver(model, g, g.get_font_small(),
CColor(10), rect);
Why is that? This works fine in MSVC++ 7, and it seems bizarre that gcc can't convert the value returned by the CRect constructor into a reference (from the error message gcc is giving me, it seems like that's what it's unable to do).
Addendum: Actually, after thinking about this for a bit I recalled from Eckel's Thinking in C++ that the return value of a function is (according to the C++ standard) supposed to be const if the function is called as a parameter to another function that takes a reference. The reasoning behind this is that the following would be pointless:
void modify_object(MyObject &object);
modify_object(MyObject());
This is because the temporary stack-allocated return value of the MyObject() constructor will be deleted at the end of the current line of code, so modifying the return value is pointless. Eckel mentions that very few compilers actually enforce this rule (clearly MSVC++ doesn't), and I think I generally agree with his opinion that it should be enforced.
So to make this code work with gcc, I'll have to make the final parameter of Testing::CPhysicsTickerObserver() be a const &CRect instead of a non-const &CRect. And this basically means I'll have to make all my methods const correct.
(as a side note, though, if I hadn't read Eckel's note and connected it to this situation, I'd still be totally lost, because the error gcc gave me for trying to do this mentioned nothing about const correctness and (as I mentioned earlier) made it seem as though the compiler didn't know how to convert a value to a reference. In fact, a lot of gcc and MSVC++'s error messages are incredibly cryptic, unlike Java's, which are usually very informative.