我想将vector/deque作为函数容器.
这种包含必须使用不同的参数来执行不同的函数.
示例功能:
program_data::getInstance().function(int,std::string);
program_data::getInstance().foo(int);
program_data::getInstance().exam(int,std::string,double);
Run Code Online (Sandbox Code Playgroud)
你能举例说明如何将这些函数与std :: vector/std :: deque和execute的参数放在一起吗?
我认为我应该使用std :: function和std :: bind但我不知道如何使用不同的args大小来支持不同的函数.
使用参数 - >我的函数(调用function foo examfrom program_data)使用参数执行一些操作.
例如:通常我执行此功能:
program_data::getInstance().function(10,"halo");
现在我想将这些函数放入std::vector // deque并执行带有函数的参数.ie(如果我将函数放在向量上面并使用(伪代码)vector[0].run();那么我的程序运行函数program_data::getInstance().function(int,std::string);)
我有一个结构:
struct a {
a(){};
a(int one,int two): a(one),b(two){};
int a;
int b;
int c;
}
a * b;
cout << b->c;
Run Code Online (Sandbox Code Playgroud)
有时当我想阅读(例如)c和debbuger时,这个值被调用
'无法读取记忆'
然后我的程序崩溃了.
现在,如何检查该值是否可读?
最好的祝福.
我反思memcpy.
我知道memcpy用于将变量复制到变量.
但是使用它并不是更好:( 例如)
int a = 5;
int b;
b = a;
Run Code Online (Sandbox Code Playgroud)
而不是memcpy?
或使用std::move替代memmove?
Memcpy并且Memmove没有过时/缓慢的功能(也许这些功能来自C)?