Thread View: comp.std.c++
1 messages
1 total messages
Started by Steve Clamage
Wed, 23 Aug 1995 15:54
Re: Template instantiation question
Author: Steve Clamage
Date: Wed, 23 Aug 1995 15:54
Date: Wed, 23 Aug 1995 15:54
34 lines
2007 bytes
2007 bytes
In article AC60F6E1966821CF0@sleipner.nts.mh.se, lars.farm@nts.mh.se (Lars Farm) writes:
>In article <41b09t$ltj@engnews2.Eng.Sun.COM>, clamage@Eng (Steve Clamage) wrote:
>
>>In the mean time, you could write a specialization of Foo<X>::compare
>>that throws an exception or invokes "assert(0)" to allow your code
>>to compile and link. That is, for example, if you use Foo<complex>,
>>you could provide the specialization
>> int Foo<complex>::compare(const complex&) { assert(0); return 0; }
>>which will prevent the compiler from generating a version from the template,
>>and will thus allow your program to compile and link.
>
>Can you specialize just that one function for complex
Yes.
>or do you have to
>specialize the whole class Foo<complex> with all its members to change the
>implementation of Foo<complex>::compare?
No. You can provide individual specializations for selected member
functions of a class if you wish. Often the template version of some
functions is acceptable, but others need a different implementation
than the version supplied by the template. This is an extreme example
where you cannot implement 'compare' at all: mathematical complex
numbers are not well-ordered.
---
Steve Clamage, stephen.clamage@eng.sun.com
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads