[英]Assign the designated function to the function member pointer?
特定
void* hello () {
cout << "Test.\n";
}
和
struct _table_struct {
void *(*hello) ();
};
我们如何将函数(hello)分配给函数成员指针?
我尝试了这个(主要):
_table_struct g_table;
_table_struct *g_ptr_table = &g_table;
// trying to get the struct member function pointer to point to the designated function
(*(g_ptr_table)->hello) = &hello; // this line does not work
// trying to activate it
(*(g_ptr_table)->hello)();
在分配指向对象的指针时,您无需取消引用。
g_ptr_table->hello = &hello; // note: the & is optional
g_ptr_table->hello(); // dereferencing the function pointer is also optional
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.