🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by John H. Spicer Tue, 22 Aug 1995 22:27
Re: Template instantiation question
#1818
Author: John H. Spicer
Date: Tue, 22 Aug 1995 22:27
44 lines
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. ]
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