Every single example out there that shows how to use a secondary index in the EOSIO platform, including the scant documentation on the function found here: https://eosio.github.io/eosio.cdt/latest/group__multiindex/#function-get_index, declares its value locally using the keyword auto, like this:

void myaction() {
    auto zip_index = addresses.get_index<name("zip")>();

As I don't need to initialise this value in every method where I use it, I'd like to declare it in my contract class and initialise it in the constructor. However, I cannot declare it in the class using auto:

/Users/ekkis/dev/eos/dapp.cpp:39:5: error: 'auto' not allowed in non-static class member auto idxtst;

can anyone tell me how to properly declare the correct type?

1 Answer 1


I saw this question that is 2 months old already but still unanswered, so I thought I could reply to it for record, since it had quite a few visualisations...

Actually the function get_index<IndexName>() is a template function and depending on the template argument that specifies the index you want to get, then a specific type can be returned.

It will return a multi_index::index object, which is a private wrapper struct type for a multi_index, so it is not accessible outside of the multi_index namespace.

So the short answer is that you can't declare a member to hold an multi_index::index, since it's type isn't available outside of multi_index namespace, so only get_index<...>() is capable of returning those.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.