【发布时间】:2016-10-21 04:23:56
【问题描述】:
我试图将一个结构函数指向另一个结构的另一个函数,
请考虑一下:
// Main Structure:
typedef struct
{
int GetValA(int a)
{
return a * 2;
}
} x;
typedef struct
{
int(*HGetValA)(int); // Pointer function
} hookx;
// Then
int main()
{
x v1;
hookx* v2;
v2 = (hookx*)&v1; // or 0x0 memory address
// Now declaring pointer function
v2->HGetValA = (int(*)(int))&v1.GetValA; // Pointing to function of the main structure.
}
对我来说,这看起来不错,但在编译时给了我错误:
[警告] 从 'int (x::)(int)' 转换为 'int ()(int)' [-Wpmf-conversions]
【问题讨论】:
标签: c++ pointers struct c++14 memory-address