trying to rewrite dome of the C code to C++, trying to abstract things so that we can have many different types of features tested in similar way. live on coliru
trying to form function pointers that have subclasses structures, so that i can abstract the mechanism for similar features. I cant give details on what, i have attached sample program here. any ideas appreciated. Is it possible to compile this code without the error
error: cannot convert 'void (Sample::)(Sample::sample_call_arg_s)' to 'Sample::sampleFuncType {aka void (Sample::)(call_arg_s)}'
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
struct call_arg_s
{
string time_stamp; // when the call was made
string func_name; // when the call was made
};
class Sample {
public:
Sample();
~Sample();
void initCallMap();
private:
typedef void (Sample::*sampleFuncType)(call_arg_s*);
struct sample_call_arg_s : call_arg_s
{
sampleFuncType func_pointer;
sample_call_arg_s()
{
func_pointer = NULL;
}
};
std::map<int, sample_call_arg_s> call_map;
void sampleMethod( sample_call_arg_s* );
};
void Sample::initCallMap()
{
call_map[0] = sample_call_arg_s();
call_map[0].func_pointer = &Sample::sampleMethod;
call_map[0].func_name = string("sampleMethod");
}
int main()
{
Sample* sample = new Sample();
sample->initCallMap();
return 0;
}
Rephrased: I want to have a self contained class that will contain a list of class methods which will be run based on enums assigned to them in a thread. I want to abstract the idea so that, i can perform similar operation on different scenarios.