#include <iostream>
#include <cstdlib>
template<typename Data_T>
class test
{
public:
void test_func_1(const Data_T &var)
{
std::cout << "test_func_1: " << var << std::endl;
}
};
template<typename Data_T>
struct example
{
int a;
float b;
void (test<Data_T>::*fun_ptr)(const Data_T& a);
};
template<typename Data_T>
std::vector<example<Data_T> > get_example(const Data_T&, size_t i)
{
std::vector<example<Data_T> > test_vect;
static example<Data_T> example_array[] =
{
{1, 2, &test<Data_T>::test_func_1},
};
//***Had to change the following code to prevent crashes**
for(int count=0;count <i; count++)
test_vect.push_back(example_array[0]);
return test_vect;
}
int main()
{
int i = 3;
double d = 23.78;
test<int> a;
test<double> b;
//Note the use of a non-zero value to the get_example function
//Accessing the first object in the vector - index [0]
(a.*(get_example(int(), 3)[0].fun_ptr))(i);
}