0

I want to define a vector of strings with a fixed size 3 in the multi-index table of smart contract. I search and tried different ways which I found for CPP vector like:

std::vector<string> abc(3);

But didn't worked. Any help would be appreciated.

2

EOSIO.CDT doesn't support std::array in function argument or field of multi_index struct. You can try my customized version of cdt, eoscc which supports std::array.

If you want to use official EOSIO.CDT, you had better use std::vector, but limit the number of items by yourself.

0

Consider this:

std::array<string, 3> abc;

UPDATE:

std::array causes compilation segmentation fault

You can make your own array:

class MyFixedArray {
  int a[3];
public:
  auto begin() {...}
  auto end() {...}
  ....
};

struct [[eosio::table]] TableWithArray {
     MyFixedArray values;
...

I think it should work. Didn't test that though :)

3
  • If I use this and compile the smart contract. It generates: Segmentation fault (core dumped) – Varsh Jun 9 '20 at 9:18
  • Indeed. Didn't know about that, sorry. – Teresa Jun 9 '20 at 13:07
  • If you stuck with this, consider using table/field through custom interface (adaptor). – Teresa Jun 9 '20 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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