|
From: xRxIxPx <xr...@gm...> - 2003-11-08 18:40:09
|
At 10:50 11/8/2003 +0100, adel essafi wrote:
>hello list
>I have a template function problem. these are my files
>and my outputs
>************** test.h *******************
>#include <iostream>
>template <class T>
>void test(T x);
>****************test.cpp ***************
>#include "test.h"
>template <class T>
>void test(T x){
> cout << x <<endl;
>}
This should be in your test.h, and the declaration can be omitted.
Templates have to be defined at compile time. When they are instanciated
(used) the compiler will create the appropriate function. So a function
test<int> can be defined in more than one object, but this is no fault and
the linker will pick one definition of the function and drop the rest.
That's it.
>****************main.cpp *************
>#include "test.h"
>main(){
> test(5);
>}
|