简体   繁体   中英

C++ passing array of pointers of methods to a method as argument

I have the following typedef:

typedef void (*Subs)(uint8_t button);

And for example this array:

 const Subs settings_sub[] = {Settings_SVA, BackToRoot};
 const uint8_t settings_size = 2;

Where "Settings_SVA, BackToRoot" are methods of the type:

void Method_name(uint8_t button){}

Now my problem is a different method, that uses these arrays and simply cycles through them:

void MoveThroughItems(uint8_t button, uint8_t counter, uint8_t limit, ??? subitems) {}

I don't know what to correctly place for the '???' for subitems, which is the above mentioned array.

Currently I use Subs subitems[] which results in an error:

invalid conversion from 'void (* const*)(uint8_t)' to 'void (**)(uint8_t)

And using "void (* const*)(uint8_t)" as the type results in:

error: expected ',' or '...' before 'subitems'
error: 'subitems' was not declared in this scope

I am pretty much stuck here, maybe I missed something simple?

You need const - const Subs subitems[] because you defined const Subs settings_sub[] = {Settings_SVA, BackToRoot}; .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM