2

Is it possible to make a multi-instance table of a struct Base with a couple of virtual methods, and then store entries of derived classes and have it be able to differentiate? So ie:

struct animal {
  virtual void make_noise();
}

struct dog : animal {
  void make_noise() { print "woof!"; }
}

multi_index<N(animals), animal> animals;

and then somehow store an entry that would somehow know how to "woof!" upon retrival?

Or perhaps store a type with a whole other type as field which would implicitly have the correct method so:

struct container {
  animal myanimal
}

dog mydog;  
container c;
c.animal = mydog;

multi_index<N(animals), container> animals;

animals.emplace(get_self(), [](auto a) {
  a.animal = c.animal;
});

Or are the fields of a multi-index table limited to basic types such as string, uint16_t etc? Thanks

1 Answer 1

2

The EOS multi-index table is based on Boost multi-index containers. From this question and this question it doesn't seem possible to store classes directly as fields, but it seems possible to manage class inheritance with proper indexing and handlers.

2
  • Ok thanks, do you know about storing pointers? It seems like you can with boost::multi-index but I wonder how it would work with abi files etc Commented Oct 7, 2018 at 1:09
  • 1
    Having experimented a bit it doesn't seem you can. Commented Oct 7, 2018 at 1:27

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.