0

I found a similiar answer to my problem here. But it is not working the way I expected. So I have

void funcA(void) {
  // do sth.
}
void funcB(void) {
  // do sth.
}

typedef struct tasks {
    int val;
    void (*Start)(void);
} tasks; 

and

const tasks tasklist[] = 
    {       
        {0, funcA},
        {3, funcB}
    };

for (i=0; i < task_cnt; i++ )     
    if (tasklist[i].val == 3)
        tasklist[i]->Start();

But at "...->Start();" compiler says "expression must have pointer type".

Any ideas? Thanks

2 Answers 2

2

you have to use tasklist[i].Start() instead of tasklist[i]->Start()

this is due to the fact that a.b is used for accessing member b of object a while a->b access a member b of object pointed to by a.

you can have the full explanation here

Sign up to request clarification or add additional context in comments.

Comments

1

You access Start the same way you access val — with a dot: tasklist[i].Start().

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.