How can you force instantiation of a template?

A

Showing Answers 1 - 12 of 12 Answers

divya shukla

  • Jun 7th, 2007
 

This is what i think
Instantiation means creating object and instantiation of a template is given by
 class name object
for example
 template
class test
{
};
     so the instantiation of a template is given by
 test t1,t2;

  Was this answer useful?  Yes

Mahadev

  • Jul 8th, 2007
 

We can force the initialization of template which out creating the object template CMobile;

In the above piece of code, we have initialized the CMobile class of type int without creating the object.

  Was this answer useful?  Yes

You can force the instantiation of a specialization of the template by specifying a prototype somewhere in your code.  For example:

template <class T> class A {
T x;
void f();
};
template <class T> void A<T>::f() {}

template class A<double>; // this prototype will cause the compiler to instantiate this specialization of the template class

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions