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
May 5, 2000



Application Security Testing: An Integral Part of DevOps

Default Arguments in a Template Instantiation

Templates can have default type parameters. The compiler uses these default types when you don't provide them explicitly in a template instantiation. For example:

template < class T1=char, class T2=char > // default types
class E 
  E( T1 t1, T2 t2 ) {m1=t1; m2=t2; }
  T1 m1;
  T2 m2;

You instantiate a template with default type parameters like this:

int main()
 E  e1(0,0);//OK, explicit types provided
 E <> e2('a','b');//OK, using default types

Make sure that your template instance has a pair of empty angular brackets after the template's name when you create a template instance that uses default type values. Omitting the empty pair of angular brackets, as in the following declaration, is an error:

E e3('a','c');   //compilation error; <> missing
Danny Kalev
Comment and Contribute






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



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date