So, I'll just toss some example code at you to start:
This is the struct and its constructor:
Code:
template <class type_s> struct task {
double time;
void (*task)(type_s);
type_s args;
};
template <class type_s> void new_task(double time, void (*function)(type_s), type_s arg_struct = NULL)
{
// Instance initialization
task<type_s>* task_p = malloc(sizeof(task<type_s>));
task_p->time = time;
task_p->task = function;
task_p->args = arg_struct;
// Placing request on the queue
queue.push(task_p);
}
This is the .h:
Code:
#include <iostream>
template <class type_s> void new_task(double,void(*)(type_s),type_s arg_struct = NULL);
And this is the sample program:
Code:
typedef struct test{
int x;
int y;
} test_s;
void func_1(test_s argument)
{
int x = argument.x;
int y = argument.y;
cout<< x << y << "\n\n";
}
int main()
{
test_s t;
t.x = 2;
t.y = 3;
new_task(30,&func_1,t);
}
So this is what's happening: undefined reference to `void new_task<test>(double, void (*)(test), test)'
Why is it happening that way, as far as you can tell? Did I template something incorrectly?