Article View: comp.std.c++
Article #1855Re: Template instantiation question
From: Nathan Myers
Date: Mon, 28 Aug 1995 03:54
Date: Mon, 28 Aug 1995 03:54
39 lines
2251 bytes
2251 bytes
clamage@Eng (Steve Clamage) writes:
>tony@online.tmx.com.au (Tony Cook) writes:
>
>>Steve Clamage (clamage@Eng) 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 we instead _declare_ the specialization and not define it:
>
>> extern int Foo<complex>::compare(const complex &);
>
>>So that we see an error at link time rather than run-time?
>
>No. The declaration does not prevent instantiation if any use is made
>of the function. That is, the declaration tells the compiler that
>particular compare function is supposed to exist. If it is needed
>but not found at link time, the system will generate it from the
>template definition.
(I'm sorry to jump in late.)
Sorry, I don't think this is right. As I understand it, declaring
a specialization before every place it is used *does* prevent
automatic instantiation. It's a violation of ODR (not required
to be detected) if you miss declaring it first, though, in one or
more places.
Nathan Myers
myersn@roguewave.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. ]
Technical Details
Message-ID:
<ncmDDzo9o.9Bx@netcom.com>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageReferences:
<41b09t$ltj@engnews2.Eng.Sun.COM> <199508220325.NAA11355@online.tmx.com.au> <41cvdk$4bp@engnews2.Eng.Sun.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: ncm@netcom.com (Nathan Myers) Newsgroups: comp.std.c++ Subject: Re: Template instantiation question Date: 28 Aug 1995 03:54:25 GMT Organization: NETCOM On-line Communication Services (408 261-4700 guest) Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <ncmDDzo9o.9Bx@netcom.com> References: <41b09t$ltj@engnews2.Eng.Sun.COM> <199508220325.NAA11355@online.tmx.com.au> <41cvdk$4bp@engnews2.Eng.Sun.COM> NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text Content-Length: 1416 Originator: clamage@taumet