devxlogo

Default Template Argument

Default Template Argument

Like ordinary functions, templates can have default type arguments. A good example is STL’s vector. 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  > //definition of the standard vector container	class vector { /*_*/ };

The default argument enables you to use vector like this:

 vector vi; //second template arguments needn't be supplied since it has a default value
See also  Small Business Strategies with Venmo
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist