function-pointers

    0热度

    2回答

    我不知道如何从构造函数上传递的函数指针初始化成员函数.. 我的类有一个成员函数RHS,它改变了差分问题的函数..所以我需要在构造函数中传递一个函数! 什么是正确的方法? class RhsOdeProblem { public: // constructor without alalitical solution constexpr RhsOdeProblem

    1热度

    3回答

    我想从二维数组中获得对角线值的值。例如.. 10 20 30 10 20 30 10 20 30 从我的代码,我将增加/从索引数[0]具有索引1和索引[2] [2]使用指针,其将计算到60 [0]求和。但是,当我构建并运行时,它将返回内存地址的计算。任何人都可以在这里解释问题? (我是新的C编程和指针) void diagonals2D(int array[][SIZE], int row

    0热度

    1回答

    我想这个方法传递: QScriptValue ScriptProcessContext::construct(QScriptContext * ctx, QScriptEngine *) { return this->newInstance(); } 到QScriptEngine::newFunction。我尝试了以下选项: 如文档and also this example co

    4热度

    3回答

    我有一个数组,看起来像这样: void* functions[]; // pointer to functions, each function returns an int and has int parameters A and B 我想丢在下面这段: int (*F)(int a, int b) = ((CAST HERE) functions)[0]; int result = F(

    2热度

    1回答

    我正在实现与字符串关键字相关联的成员变量指针映射。 所有变量的范围从基类“BaseA” 从映射访问变量时,只需要使用基类方法(示例中的getDesc()),因此不需要检索原始类型。 该代码编译并在GNU g ++ 6.2.1下运行,但根据我所读到的,reinterpret_cast的使用不可移植,并且可能无法与其他编译器一起使用。 这是正确的吗?还是这个代码符合C++标准? 有没有其他的方式来做到

    1热度

    2回答

    我想创建一个函数,它返回一个函数指针数组指针(即一个指针指向一个其元素为函数引脚的数组)。我宣布它是这样的: void (*(*getFuncArrayPointer(int flag)))[3]{} 但我得到的错误: returnFuncAttrPointer.c:27:10: error: declaration of ‘getFuncArrayPointer’ as array of v

    6热度

    1回答

    这或多或少澄清 Casting a function pointer to another type与示例代码的请求 struct my_struct; void my_callback_function(struct my_struct* arg); void do_stuff(void (*cb)(void*)); static void my_callback_helper(void

    0热度

    2回答

    我目前有一个typedef指针函数,它不会指向任何导致分段错误(核心转储)的东西。我试图想出一个解决方案来避免它,但目前还没有想到。 我的代码: typedef void (*MenuFunction)(System*); int main(int argc, char ** argv) { ... /* While loop for my menu */ wh

    1热度

    2回答

    我有以下代码: typedef int state_requester(void* request_paramaters); int doSomething(state_requester* requester) { // This if statement is what I'm trying to // figure out how to do. if (

    4热度

    3回答

    我正在尝试编写一个模板类的函数,它接受一个参数,该参数是大类的私有数据中的成员类的函数指针。当你调用该成员时,它会在较小的类上调用该函数。 (?混淆右)为了证明,我这里有一个非工作例如: #include <vector> #include <iostream> using namespace std; template <typename T, typename C> struct