There is a universal function start , which takes as input a pointer to an unknown function that must be executed and an array of unknown parameters, one of which must be passed to this function as input, that is:
typedef void(*func_t)(void*); This universal function (or a method of a certain class) knows nothing about the obtained function or data array, except for one thing - which element of the array should be passed to the obtained function as input.
Tell me how it can be done using 2 parameters, i.e .:
void MyFunc(void* params) { CMyParams* data = (CMyParams*)params; // основной код } CMyParams* myAllData = new CMyParams[1000]; start(MyFunc, myAllData); Where
void start(func_t func, void* data) { const int index = 123; // единственный параметр о котором знает функция start func(&data[index]); } And with this way of passing the parameters, I have a problem, but my head doesn’t cook something. Probably it should pop up void** , but do not catch :(
I solved this problem by passing the third index parameter to the func_t function, but this is a pure crutch. And how to do without it?
And I want the start function not to know anything about the function and the data it receives at all - not her business.
PS
The fact is that, in addition to index , the start function also knows about the amount of the transferred amount array and must not just call the function, but call a function with different parameters (i.e., in a loop)
for (index = 0; index < amount; index++) { func(&data[index]); }
startimmediately a pointer to the 123rd object. - VTTstartfunction, besidesindex, also knows about the amount array being transferred, and should not just call the function, but call the function with different parameters (i.e. in a loop) - Zhihar