This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: problems with template instantiation
- To: John McCurry <john dot mccurry at talk21 dot com>
- Subject: Re: problems with template instantiation
- From: Gabriel Dos Reis <gdr at codesourcery dot com>
- Date: 22 Aug 2000 16:54:35 +0200
- Cc: gcc at gcc dot gnu dot org
- Organization: CodeSourcery, LLC
- References: <39A2986A.5B4F6CA7@talk21.com>
John McCurry <john.mccurry@talk21.com> writes:
| Hi folks,
|
| I expect this to be a trivial problem for someone who has more
| experience with the GNU compiler than I do.
| The problem is that I can't get the compiler to automatically create the
| required instantiations of template
| classes (which I think it should do). I hope the following example will
| illustrate the point:
|
| I have built a trivial application from the 3 files: a.h, a.cxx and
| main.cxx
|
| FILE a.h:
|
| template <class T> class A
| {
| public:
| A();
| A(const T& t);
| ~A();
| T getValue() const;
|
| private:
| T value;
| };
|
| <EOF>
|
|
| FILE a.cxx:
|
| #include "a.h"
|
| template <class T> A<T>::A() {}
| template <class T> A<T>::A(const T& v) { value = v; }
| template <class T> A<T>::~A() {}
| template <class T> T A<T>::getValue() const { return value; }
|
| <EOF>
|
|
| FILE main.cxx:
|
| #include <iostream.h>
| #include "a.h"
That can't work. The "standard" way of making it to work is through
use of the keyword "export". However, G++ doesn't understand export;
so you have to make your template definitions visible to the compiler
whenever they get instantiated (for example by #including a.cxx at the
end of a.h).
Please, notice that this list is about GNU compilers development;
gcc-bugs is for bugs found in GCC. Any C++ specific question is to be
sent to dedicated forums.
-- Gaby
CodeSourcery, LLC http://www.codesourcery.com