2

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.

3

2 Answers 2

7

You can just assign the pointer to the function like:

func = &virDomainCreate;

Or you can just use the short format:

func = virDomainCreate;
Sign up to request clarification or add additional context in comments.

2 Comments

I would add that maybe func = &virDomainCreate is the safe way to do it.
1

The return type is int so

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

will work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.