Article View: comp.std.c++
Article #1818Re: Template instantiation question
From: John H. Spicer
Date: Tue, 22 Aug 1995 22:27
Date: Tue, 22 Aug 1995 22:27
44 lines
2040 bytes
2040 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.
That *particular* declaration doesn't prevent an instantiation
from being generated, but if the declaration
template <> int Foo<complex>::compare(const complex &);
is present wherever the function is called, it will prevent an
instantiation from being generated.
(or at least it will eventually when this is supported by compilers)
John Spicer
Edison Design Group
---
[ 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:
<MATT.95Aug22152733@physics2.Berkeley.EDU>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt From: "John H. Spicer" <jhs@edg.com> Newsgroups: comp.std.c++ Subject: Re: Template instantiation question Date: 22 Aug 1995 22:27:33 GMT Organization: <none> Approved: matt@physics2.Berkeley.EDU (Matt Austern) Message-ID: <MATT.95Aug22152733@physics2.Berkeley.EDU> NNTP-Posting-Host: physics2.berkeley.edu