I was wondering if there was a way to initialize a function and place a pointer within a struct so that I can in some effect create a macro to create a function, rather than having two separate macros (one for function, one for array).
class MyFunctor
{
int *_theData;
public:
MyFunctor(int *data) : _theData(data)
{ }
//Operator() overload:
voidoperator()(/* Some other parameters here, if needed */)
{
//Do something with the data.
...
}
};
//Then create functors and use them.
int main()
{
int array1[] = { 1, 2, 3 };
int array2[] = {4, 5, 6 };
MyFunctor functors[] = { MyFunctor(array1), MyFunctor(array2) };
//Call the functors.
for (int i = 0; i < _countof(functors); i++)
{
functors[i]();
}
return 0;
}
Seem to be unable to convert to a pointer to a function (visual studio only bug?), is there any way to define a variable to take a lambda like I would in a structure for a function pointer?
1 2 3 4 5 6 7 8 9 10 11 12
struct A
{
void (* funct_ptr)();
// somehow define a lambda variable here instead ? is there syntax for this?
};
A a = {
[] () { /* do something */ } // error unable to convert "lambda [] void -> void" to void (*)()
};