By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,099 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

Template specialization and partial specialization

P: n/a
Does VC 7.1 support template specialization and partial specialization ?

Nov 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Alfonso Morra wrote:
Does VC 7.1 support template specialization and partial
specialization ?


Yes.
Nov 17 '05 #2

P: n/a


Carl Daniel [VC++ MVP] wrote:
Alfonso Morra wrote:
Does VC 7.1 support template specialization and partial
specialization ?

Yes.


Do I have to define my specializations insitu (in header file), or can I
define them elsewhere (in a .cpp file)?. There seems to be some
confusion in this matter, wrt VC 7.1

Nov 17 '05 #3

P: n/a
Alfonso Morra wrote:
Carl Daniel [VC++ MVP] wrote:
Alfonso Morra wrote:
Does VC 7.1 support template specialization and partial
specialization ?


Yes.


Do I have to define my specializations insitu (in header file), or
can I define them elsewhere (in a .cpp file)?. There seems to be some
confusion in this matter, wrt VC 7.1


All template definitions, specialization or not, must be visible at the
point of use. In practice, that means they must be in a header file.

At present, this is true for all C++ compilers except Comeau, which remains
the only compiler to have a supported implementation of the C++ 'export'
facility. Using 'export', you can place your template deifnitions in a
"cpp" file.

-cd
Nov 17 '05 #4

P: n/a
Alfonso Morra wrote:


Carl Daniel [VC++ MVP] wrote:
Alfonso Morra wrote:
Does VC 7.1 support template specialization and partial
specialization ?


Yes.


Do I have to define my specializations insitu (in header file), or can I
define them elsewhere (in a .cpp file)?. There seems to be some
confusion in this matter, wrt VC 7.1


Declarations of all partial class template and explicit function and
class template specializations should always go in headers (for all
compilers), since the declaration of a specialization must appear before
that specialization is used, otherwise the code has undefined behaviour.
Explicit class template specializations should also be defined in the
header (otherwise they will be incomplete types).

Definitions of members of partial specializations should generally go in
headers (except when your compiler supports "export", which VC does not).

Definitions of explicit function template specializations or members of
explicitly specialized class templates should go in .cpp files (unless
declared inline, or defined in the class body).

I hope that is reasonably clear. Visual C++ implements the "Borland"
model of template instantiation, where definitions of non-explicit
template specializations must always be visible at the point of
instantiation.

Tom
Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.