Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > What's the difference betwwen explicit instantiaion and explicit specialization?

Reply
Thread Tools

What's the difference betwwen explicit instantiaion and explicit specialization?

 
 
Andy
Guest
Posts: n/a
 
      01-30-2005
Hi,

I got a little confused on 'instantiation' and 'specialization',
espcially for explicit instantiation and explicit sepcialization. Can
anybody explain the difference?

Thanks a lot!

Andy

 
Reply With Quote
 
 
 
 
Andy
Guest
Posts: n/a
 
      01-30-2005
Is an instantiation a process of producing a specialization?
Thanks,

andy

 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      01-30-2005
* Andy:
>
> I got a little confused on 'instantiation' and 'specialization',
> espcially for explicit instantiation and explicit sepcialization. Can
> anybody explain the difference?


You specialize a template when you provide a definition for some actual
template parameter, e.g., saying "in general, use the general definition,
but for template parameter T=int, use this more specialized definition".

This specialized definition may or may not be actually used, so
specialization by itself does not cause a more thorough analyzis than
the original template definition.

You instantiate a template when you cause the compiler to generate code for
the template. This requires all template parameters given actual parameters,
and it causes full-blown analysis of this specialization of the template.
For example, you declare an object of the template type, or you call a
templated function. At that point the template definition is expanded to
actual, ordinary C++ code (the template instance), which is subject to the
usual C++ compilation (OK, some rules, e.g. about multiple definitions, are
slightly different). You can also instantiate a template without using it, via
special syntax.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
 
Reply With Quote
 
Shezan Baig
Guest
Posts: n/a
 
      01-30-2005

Andy wrote:
> Hi,
>
> I got a little confused on 'instantiation' and 'specialization',
> espcially for explicit instantiation and explicit sepcialization.

Can
> anybody explain the difference?
>
> Thanks a lot!
>
> Andy


If I have a templated class:

template <typename FOO> class Bar { ... };

I explicitly *instantiate* Bar<char> like this:

template <> class Bar<char>;

Notice that the implementation of Bar<char> does not change (i.e., it
is not specialised).

When I *specialise* Bar<char>, I do this:

template <> class Bar<char> { ... };

Now, Bar<char> has a new meaning (i.e., the template class 'Bar' now
does something "special" when used with 'char' as the template
argument).

Hope this helps,
-shez-

 
Reply With Quote
 
Max M.
Guest
Posts: n/a
 
      01-30-2005
Shezan Baig wrote:
>
>
> I explicitly *instantiate* Bar<char> like this:
>
> template <> class Bar<char>;
>


The correct syntax for explicit instantiation is

template class Bar<char>;

(with no '<>'.)


MM




 
Reply With Quote
 
Shezan Baig
Guest
Posts: n/a
 
      01-30-2005

Max M. wrote:
> Shezan Baig wrote:
> >
> >
> > I explicitly *instantiate* Bar<char> like this:
> >
> > template <> class Bar<char>;
> >

>
> The correct syntax for explicit instantiation is
>
> template class Bar<char>;
>
> (with no '<>'.)
>
>
> MM


Yes, this is correct. My bad.

-shez-

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exchanging data betwwen threads? Solang C++ 3 09-20-2009 05:55 PM
How copy dir when there is a space betwwen cyrusgreats@gmail.com Perl Misc 2 06-22-2007 05:10 PM
Explicit instantiation of STL vector demands explicit instantiation of all the templates it using internally. krunalbauskar@gmail.com C++ 1 12-25-2006 03:51 PM
what's the difference betwwen these two ways to use std::ofstream thinktwice C++ 2 08-25-2006 05:44 AM
Is explicit template qualification required for explicit delete? J.T. Conklin C++ 1 08-11-2004 02:06 AM



Advertisments