[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Undefined reference to '...'



On Sep  2, 1997, at 20:11, Orn E. Hansen wrote:
 >   I tried using the 'template class ...' and that did the trick,
 > but I agree that it is of limited use though.  Kinda limits the
 > generality of your code, if you have to know the type ofevery
 > template class before hand.  So, I'm going to look up the site
 > you suggested and try their snapshot.

Let me add my 0.01c...

The only official way sanctioned by the upcoming C++ ANSI/ISO standard
to instantiate templates is to explicitly mention the types you want
to use for instantiation. All of the repository techniques that exist,
some better, some worse, are not standard and that's one reason why
you do this differently on each platform.

If you ask me, explicit instantiation is the correct way, because it
gives you the control on where, when and how many times (hopefully
just once!) you instantiate something.

If your compiler supports explicit template instantiation with the
standard 'template class MyClass<int>;' mechanism (as g++ appears to),
then this is what I would do:

1. Put the class declaration in a header file by itself.
2. Put the class definition in a source file by itself.
3. Put the template instantiation at files where you actually use the
   template. Preferably, put them in a file just by themselves; this
   way, it is easier to control whether you have instantiated a
   template or not.
4. It is important not to mix templated code and non-templated code in
   one file (as in point (2) above); this way, you avoid multiple
   definitions just because you instantiate two templates of the same
   class with different type parameters on two separate files.

Hope this helps.

-- 
Gonzalo A. Diethelm G.
gonzo@ing.puc.cl


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org . 
Trouble?  e-mail to templin@bucknell.edu .


Reply to: