Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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.



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