This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Problem declaring template class functions


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]