problems with gcc
Gokhan Kisacikoglu
kisa@centropolisfx.com
Fri Jul 26 14:58:00 GMT 2002
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
More information about the Gcc-help
mailing list