我希望能够在类中使用我的 typedef 函数。但我找不到办法做到这一点。我需要扫描地址,所以我不能硬编码,因此我需要像这样设置地址 SetCursorPosFunction = (_SetCursorPos)(address to function);
例子:
class Cursor
{
public:
typedef BOOL(__stdcall *_SetCursorPos) (int X, int Y);
_SetCursorPos SetCursorPosFunction;
};
我希望能够像这样调用函数 Cursor::SetCursorPosFunction(x,y)
我的意思的例子。
void Function()
{
DWORD_PTR AddressToFunctionSetCourserPos = Find(....);
Cursor::SetCursorPosFunction = (Cursor::_SetCursorPos)(AddressToFunctionSetCourserPos ); //In final version it is going to be in a separate function where i get all the functions i need (This find() function can not be looped or called often, it is going to create lag etc.).
Cursor::SetCursorPosFunction(1, 1);
}
我得到错误:
fatal error LNK1120: 1 unresolved externals
error LNK2001: unresolved external symbol "public: static int (__cdecl* Cursor::SetCursorPosFunction)(int,int)" (?SetCursorPosFunction@Cursor@@2P6AHHH@ZEA)
最佳答案
将函数修改为static
将允许您使用它而不必根据需要先实例化一个成员:
class Cursor
{
public:
typedef BOOL(__stdcall *_SetCursorPos) (int X, int Y);
static _SetCursorPos SetCursorPosFunction;
};
Cursor::SetCursorPosFunction(x,y)
现在应该可以工作(前提是您首先对其进行了初始化)。
您还需要在全局空间中初始化静态成员。像 Cursor::_SetCursorPos Cursor::SetCursorPosFunction = nullptr;
这样的东西应该可以工作。但要注意只在一个翻译单元中使用它。
关于c++ - 类中的 Typedef 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51899619/