C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

What's the difference betwwen explicit instantiaion and expl

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Andy
Guest





PostPosted: Sun Jan 30, 2005 9:34 am    Post subject: What's the difference betwwen explicit instantiaion and expl Reply with quote



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

Back to top
Andy
Guest





PostPosted: Sun Jan 30, 2005 9:40 am    Post subject: Re: What's the difference betwwen explicit instantiaion and Reply with quote



Is an instantiation a process of producing a specialization?
Thanks,

andy

Back to top
Alf P. Steinbach
Guest





PostPosted: Sun Jan 30, 2005 9:49 am    Post subject: Re: What's the difference betwwen explicit instantiaion and Reply with quote



* Andy:
Quote:

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?

Back to top
Shezan Baig
Guest





PostPosted: Sun Jan 30, 2005 4:27 pm    Post subject: Re: What's the difference betwwen explicit instantiaion and Reply with quote


Andy wrote:
Quote:
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-


Back to top
Max M.
Guest





PostPosted: Sun Jan 30, 2005 4:36 pm    Post subject: Re: What's the difference betwwen explicit instantiaion and Reply with quote

Shezan Baig wrote:
Quote:


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





Back to top
Shezan Baig
Guest





PostPosted: Sun Jan 30, 2005 11:46 pm    Post subject: Re: What's the difference betwwen explicit instantiaion and Reply with quote


Max M. wrote:
Quote:
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-


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.