I created a small project and listing out the files below
//test.h
Code:
#include <iostream>
template<typename Data_T>
class test
{
public:
test test_func_1(const Data_T &var);
};
template<typename Data_T >
test test<Data_T>::test_func_1(const Data_T &var)
{
std::cout << "test_func_1: " << var << std::endl;
}
//test2.h
Code:
#include <iostream>
#include <test.h>
template<typename Data_T> class test;
template<typename Data_T>
struct example
{
int a;
float b;
test<Data_T> (test<Data_T>::*fun_ptr)(const Data_T& a);
};
example<int> example_array[] =
{
{1, 2, &test<int>::test_func_1},
{1, 2, &test<int>::test_func_1},
};
//main.cpp
Code:
#include <iostream>
#include <test2.h>
int main()
{
std::cout<<"test_func"<<example_array[0].a<<std::endl;
}
I can not include test.h file in test2.h file because if i do so then it gives error at
Code:
template<typename Data_T >
test test<Data_T>::test_func_1(const Data_T &var) //error: expected constructor, destructor, or type conversion before ‘test’
{
std::cout << "test_func_1: " << var << std::endl;
}