![]() |
don't understand this code.. - Printable Version +- Forums (https://www.vdrift.net/Forum) +-- Forum: Project (https://www.vdrift.net/Forum/forumdisplay.php?fid=4) +--- Forum: Development (https://www.vdrift.net/Forum/forumdisplay.php?fid=9) +--- Thread: don't understand this code.. (/showthread.php?tid=1017) |
don't understand this code.. - ghiboz - 11-13-2008 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 - osteron - 11-13-2008 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 ![]() - ghiboz - 11-14-2008 thanks, so in some part of the code is there a definition of T used by a double for example - joevenzon - 11-16-2008 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. - ghiboz - 11-17-2008 thanks joe! :wink: |