Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
don't understand this code..
11-13-2008, 12:24 PM,
#1
don't understand this code..
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
www.ghiboz.com
Reply
11-13-2008, 12:45 PM,
#2
 
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
Reply
11-14-2008, 09:09 AM,
#3
 
thanks, so in some part of the code is there a definition of T used by a double for example
www.ghiboz.com
Reply
11-16-2008, 05:06 PM,
#4
 
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.
Reply
11-17-2008, 03:55 AM,
#5
 
thanks joe! :wink:
www.ghiboz.com
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)