you can instantiat a template in two ways. 1. Implicit instantiation and 2. Explicit Instantion. implicit instatanitioan can be done by the following ways:<br><br>template <class T><br><br>class A<br><br>{<br><br>public: <br><br>A(){}<br><br>~A(){}<br><br>void x();<br><br>void z();<br><br>};<br><br>void main()<br><br>{<br><br>A<int> ai;<br><br>A<float> af;<br><br>}<br><br>External Instantion can be done the following way:<br><br>int main()<br><br>{<br><br>template class A<int>;<br><br>template class A<float>;<br><br>}<br>
C++
Topic: Templates
How can you force instantiation of a template?
Browse random answers:
What is a template?
Can we have "Virtual Constructors"?
How can you force instantiation of a template?
What is namespace?
When is a template a better solution than a base class?
How do you implement thread synchronization (Object.Wait, Notify,and CriticalSection) in C#?
What is a friend function & its advantage?
Differentiate between a template class and class template?
What is the Standard Template Library (STL)?
When is a template a better solution than a base class?
What are the Function templates ?
What are Class templates ?
Explain about Template specialization ?
Explain about Non-type parameters for templates ?
Explain the Templates and multiple-file projects ?
What are the syntax and semantics for a function template?
Differentiate between a template class and class template.
My compiler says that a member of a base class template is not defined in a derived class template. Why is it not inherited? template<typename T>class base {public: void base_func();};template<typename T>class derived : public base<T> {public: void derived_func() { base_func(); // error: base_func not defined }};
Is it possible to specialise a member function of a class template without specialising the whole template?
Why do I need to add "template" and "typename" in the bodies of template definitions?
Is there a difference between a function template and a template function, or between a class template and a template class?