This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Problem declaring template class functions
- To: ivan_m_r at email dot com
- Subject: Re: Problem declaring template class functions
- From: Alexandre Oliva <aoliva at cygnus dot com>
- Date: 19 Apr 2000 16:45:57 -0300
- Cc: gcc-help at gcc dot gnu dot org
- Organization: Cygnus Solutions, a Red Hat Company
- References: <38FDF232.8346BE3A@kalman.iau.dtu.dk>
On Apr 19, 2000, Ivan Martinez <ex08@kalman.iau.dtu.dk> wrote:
> I have a template class declared in a header file like this:
> Its functions are declared in a code file like this:
> Why when I try to call the functions I get a "undefined reference
> to..." error?
Because the *definition* of a template (not just the declaration) must
be available in any translation unit that refers to the template,
unless it is explicitly instantiated or exported in some other
translation unit. Since GCC doesn't support `export' yet, you must
either #include the definition file in the header file or provide
explicit instantiations of the templates in the definition file.
> I address this question to this list because I heard GCC is a bit
> different to standard in this issues.
Nope, it's totally standard, except for the lack of `export'. Some
other compilers are non-standard, implicitly searching for definitions
in `.cc' or `.cpp' files.
--
Alexandre Oliva Enjoy Guaranį, see http://www.ic.unicamp.br/~oliva/
Cygnus Solutions, a Red Hat company aoliva@{redhat, cygnus}.com
Free Software Developer and Evangelist CS PhD student at IC-Unicamp
oliva@{lsd.ic.unicamp.br, gnu.org} Write to mailing lists, not to me