Teach Time Encyclopedia - Learn About Our World
Home Page
Teach Time
Featured Topics

United States
by state

CITYology

Academic Disciplines

Historical Timelines

Themed Timelines

Calendars

Reference Tables

Biographies

How-tos



Monday, October 13, 2008

Template (programming)

In computer programming, templates allow code to be written without consideration of the data-type with which it will eventually be used. They are a feature of C++, Ada and some other languages.

Templates are similar to macros, in that they are interpreted by the preprocessor and don't reduce efficiency. However templates are type-safe, which encourages the writing of error free code.

Templates were left out of some C++ derived languages, such as Java and C#, because these languages have other methods of dealing with the same problems. However templates are of great utility to programmers in C++, especially when combined with multiple inheritance and operator overloading. The Standard Template Library (STL) for C++ provides many useful functions within a framework of connected templates.

There are two kinds of templates. A "class template" is often used to make a generic container. For example, the STL has a linked list container. To make a linked-list of integers, you write "list". A list of strings is denoted "list". A list has a set of standard functions associated with it, which work no matter what you put between the brackets.

There are also function templates. For example, the STL contains the function "max(x,y)", which returns either x or y depending on which is larger. This works whether x and y are integers, strings, or any other type for which it makes sense to say "x < y". If you have defined your own data type, you can use operator overloading to define the meaning of "<" for your type, thus allowing you to use the max function. While this may seem a minor benefit in this isolated example, in the context of a comprehensive library like the STL it allows the programmer to get extensive functionality for a new data type, just by defining a few operators for it.



Internet Hotel Solutions

Site Sponsors
AC Units
Baltimore Harbor
Boot Camp Grads
Bra Size
Burkittsville
College Hotels
Digital Harbor
Free Cell Phones
Golden Hare Travel
Golf Vacations
Golf Courses
Gourmet
Hair Styles
Hippodrome
iWoman
Lesson Plans
Maryland Hotels
MD Genealogy
Minor League Stuff
Motel Site
Ocean City
OC Real Estate
Old Agers
Office Supplies
Orlando
Pet Friendly Hotel
Room Prices
Savannah, GA
Ski Vacations
South Baltimore
Student Teaching
Travel Sources
University Hotels
Visit Military Bases
Washington, DC

Brought to you by NoChildLeftBehind.com and the Beaches and Towns Network, LLC.