This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: problems with gcc
- From: Gokhan Kisacikoglu <kisa at centropolisfx dot com>
- To: Andreia R de Assuncao Schneider <andreia at comp dot ufla dot br>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 26 Jul 2002 15:01:11 -0700
- Subject: Re: problems with gcc
- Organization: Centropolis Effects, LLC
- References: <Pine.LNX.4.44.0207261720450.1917-100000@localhost.localdomain>
- Reply-to: kisa at centropolisfx dot com
Andreia R de Assuncao Schneider wrote:
>
> Hi,
> I made my program separating the files .h (declarations) and .cpp
> (definitions), but some classes have template, and the gcc gives
> linkage error. I was informed that the gcc doesn't accept this
> separation. Someone can say me why this problem occur? How can I do?
> Do I do the declaration and the definition only in a file .h,
> or there is a solution for this problem?
>
This is standard, you have to put your template definitions into the
header files so that the compiler will instantiate these functions when
it needs for different types. If you think it is getting messy, you can
also organized your code in the header/inline file form;
-------- foo.h --------------
#ifndef _foo_h_
#define _foo_h_
#include includes
template <class C>
class foo
{
public:
foo();
void doSomethingFn(const C &_value);
}
#include "foo.inl"
#endif // _foo_h_
------------------------------
--------- foo.inl ------------
#ifndef _foo_inl_
#define _foo_inl_
// all of the inline and template
// functions here
//
template <class C>
foo<C> :: foo()
{
}
template <class C>
void
foo<C> :: doSomethingFn(const C &_value>
{
// fn body
}
#endif // _foo_inl_
-------------------------------
Your makefile will still compile everything when you change something in
the foo.inl though, because it is part of the include file that is now
only organized better...
HTH,
Gokhan