Forums

Full Version: don't understand this code..
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all (especially joe :wink: )
I'm looking your new code...
example cartire.h....

what means the T datatype?
template <typename>
??
i feel hard understand this...
thanks in advance!

ghiboz
I guess that it means that you can use it universally.
On objectcreation you specify what type you want to use e.g.
CARTYRE <int> tire;
And then all occurrences of T will be replaced by the specified type.

Others will probably explain it better Smile
thanks, so in some part of the code is there a definition of T used by a double for example
Here's a pretty good introduction to templates (specifically see the section on Class Templates):
http://www.cplusplus.com/doc/tutorial/templates.html

In the car.h file you'll see CARDYNAMICS <double> dynamics, which means that for all of the car classes "double" gets substituted for T. I did it this way in case I wanted to try using a 32-bit float instead of a 64-bit double.
thanks joe! :wink: