-1
我已閱讀上如此相似線程關於這個主題(How to initialize a Pointer to a struct in C?和 Initializing a pointer to a structure) ,但沒有試圖new
或malloc
的結構。我有一大堆的typedefs
像初始化指針的typedef
typedef void (*STP_CALLBACK_ON_TOPOLOGY_CHANGED) (BRIDGE* bridge);
typedef void* (*STP_CALLBACK_ALLOC_AND_ZERO_MEMORY) (unsigned int size);
typedef void (*STP_CALLBACK_FREE_MEMORY) (void* p);
typedef void (*STP_CALLBACK_ENABLE_LEARNING) (BRIDGE* bridge, unsigned int portIndex, unsigned int treeIndex, bool enable);
形成一個結構
struct STP_CALLBACKS
{
STP_CALLBACK_ON_TOPOLOGY_CHANGED onTopologyChanged;
STP_CALLBACK_ALLOC_AND_ZERO_MEMORY allocAndZeroMemory;
STP_CALLBACK_FREE_MEMORY freeMemory;
...
};
,當我想初始化一個指向該結構
const STP_CALLBACKS *callbacks = new STP_CALLBACKS;
它實際上inits什麼。我是一個新手,顯然錯過了一些重要的事情。什麼是正確的做法?
P.S.上面的代碼是從mstp-lib。我在VS2015。
它們是函數指針.... –
你想用什麼初始化它們? – doctorlove
@doctorlove在下一個函數中使用 - [STP_CreateBridge](https://sourceforge.net/p/mstp-lib/code/HEAD/tree/trunk/_help/STP_CreateBridge.html) – Alexandr