🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1814

Re: Template instantiation question

#1814
From: Steve Clamage
Date: Tue, 22 Aug 1995 18:22
30 lines
1924 bytes
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.

--
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. ]
Technical Details
Message-ID: <41cvdk$4bp@engnews2.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
References: <41b09t$ltj@engnews2.Eng.Sun.COM> <199508220325.NAA11355@online.tmx.com.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: clamage@Eng (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: Template instantiation question
Date: 22 Aug 1995 18:22:05 GMT
Organization: Sun Microsystems Inc., Mountain View, CA
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <41cvdk$4bp@engnews2.Eng.Sun.COM>
References: <41b09t$ltj@engnews2.Eng.Sun.COM> <199508220325.NAA11355@online.tmx.com.au>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: taumet.eng.sun.com
X-Newsreader: NN version 6.5.0 #21 (NOV)
Content-Length: 1062
Originator: clamage@taumet