Defining a templated class method

How do I define a foward declared templated class,

This is what I am trying to do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

template< class T >
struct data_t {
    T data;

    void change( T _data ){
         data = _data;
    }
};

int main()
{
    data_t<float> test;
    return 0;
}


Then I try doing this one below
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

using namespace std;

template< class T >
struct data_t {
    T data;

    void change( T _data );
};

template< class T >
void data_t::change( T _data ){
    data = _data;
}

int main()
{
    data_t<float> test;
    return 0;
}

This one doesn't compile with error
"used without template parameters"


Then I realize,
I never really know how to define a foward declared templated class method / function

I can't seems to get answer from google, maybe because I am not searching hard enough,

help me please ,,,
Last edited on
Topic archived. No new replies allowed.