>>26201
>how do you make a vector with function pointers?
Here's a quick example using C++11 lambdas, Anon. Hopefully this will get you kickstarted :
>callstack_main.cpp
// build & run :
// g++ callstack_main.cpp -std=c++14 && ./a.out
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
// a couple of arbitrary void functions :
void prt_num(int i) { cout << i << '\n'; }
void prt_dbl_num(int i) { cout << (i * 2) << '\n'; }
int main()
{
// an empty vector of void functional types
vector<function<void()>> funcs;
// store a few lambdas (aka, 'closures') into the container :
funcs.push_back([]() { prt_num(42); });
funcs.push_back([]() { prt_num(700); });
funcs.push_back([]() { prt_num(9'001); });
funcs.push_back([]() { prt_dbl_num(42); });
funcs.push_back([]() { prt_dbl_num(700); });
funcs.push_back([]() { prt_dbl_num(9'001); });
// execute all stored functionals, beginning to end
for (auto const& fn : funcs)
fn();
}
>output:
42
700
9001
84
1400
18002
Try that (adapting it to your specific usecase ofc), then let me know how it goes please. Cheers. :^)
>>26211
Thanks NoidoDev! That's good advice, and much appreciated. Cheers. :^)
>===
-
edit code example
Edited last time by Chobitsu on 11/05/2023 (Sun) 15:57:55.