Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages

Testing Namespace Reference


Compounds

class  CFPSGraphicalObserver
class  CPhysicsTickerModel
class  CPhysicsTickerObserver

Functions

void add_components (CGame &g, int num_boxes)


Detailed Description

Test classes for the framework. Horribly designed and implemented, but they get the job done.


Function Documentation

void add_components CGame g,
int  num_boxes
 

Adds some components from the test classes to the given CGame object: a single big frames-per-second observer and the given number of bouncing boxes.

C++ Annoyance:
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.

Definition at line 190 of file testing.h.

References CPanel::add(), CModel::attach(), CGame::get_font_large(), CGame::get_font_small(), CGame::tickables, and CGame::timer.

Here is the call graph for this function:


Generated on Wed Aug 27 11:59:32 2003 for GFW by doxygen 1.3.3