I have two functions,

//virDomain is some struct
int virDomainCreate(virDomain*);
int virDomainDestroy(virDomain*);

How do I assign these two functions to a variable?

I tried,

int (*func)(virDomain*) = NULL;
func = virDomainCreate(virDomain*); // not working
func = &virDomainDestroy(virDomain*); //not working

Thanks for all your help! Waka.

有帮助吗?

解决方案

You can just assign the pointer to the function like:

func = &virDomainCreate;

Or you can just use the short format:

func = virDomainCreate;

其他提示

The return type is int so

int func;
func = virDomainCreate(virDomain*); 
func = virDomainDestroy(virDomain*);

will work.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top