Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Intermediate
Aug 28, 1998

Default Template Argument

Like ordinary functions, templates can have default type arguments. A good example is STL's vector<T>. It actually has two arguments--the second one is an allocator class template. Since an allocator is something you should rarely care about, it has a default value: the implementation's allocator, which spares you the bother of specifying an allocator type every time you use it:
 
template<class T, class A = allocator<T>  > //definition of the standard vector<T> container
	class vector { /*_*/ };
The default argument enables you to use vector<T> like this:
 
vector<int> vi; //second template arguments needn't be supplied since it has a default value
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date