function-pointers

    4熱度

    3回答

    我正在嘗試編寫一個模板類的函數,它接受一個參數,該參數是大類的私有數據中的成員類的函數指針。當你調用該成員時,它會在較小的類上調用該函數。 (?混淆右)爲了證明,我這裏有一個非工作例如: #include <vector> #include <iostream> using namespace std; template <typename T, typename C> struct

    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 (