0

As we know from the documentation, a table must be initialized as shown below:

class [[eosio::contract]] helloworld: public eosio::contract
{
public:
   helloworld(eosio::name receiver, eosio::name code, eosio::datastream<const char*> ds)
   : contract(receiver, code, ds),
     my_table(receiver, receiver.value) { }

   ///////////////

   struct [[eosio::table]] testtable_j
   {
      name owner;
      std::string data;
      uint64_t primary_key() const { return owner.value; }
   };
   using testtable_t = eosio::multi_index<"testtable"_n, testtable_j>;
   testtable_t my_table;
}

But how can I declare my table outside of class 'helloworld'? For using its type without binding to it (in other .hpp/.cpp files for example). This case doesn't work - precisely speaking, abi not generated. But compilation is ok:

struct [[eosio::table]] testtable_j
{
      name owner;
      std::string data;
      uint64_t primary_key() const { return owner.value; }
};
using testtable_t = eosio::multi_index<"testtable"_n, testtable_j>;

///////////////

class [[eosio::contract]] helloworld: public eosio::contract
{
public:
   helloworld(eosio::name receiver, eosio::name code, eosio::datastream<const char*> ds)
   : contract(receiver, code, ds),
     my_table(receiver, receiver.value) { }
   
   testtable_t my_table;
}

2 Answers 2

1

to everyone who is interested - I used a "void*"

.hpp:

void my_method(const name& wax_user, const void* table_itr_ptr);

.cpp:

void my_method(const name& wax_user, const void* table_itr_ptr)
{
   helloworld::testtable_t::const_iterator itr_c = *(static_cast<const helloworld::testtable_t::const_iterator*>(itr_ptr));
   const helloworld::testtable_j& item = *itr_c;
   // ...
   
}

using:

helloworld::testtable_t::const_iterator itr_c = game.get_table_items().require_find(item_id, "error"));
my_method(wax_user, &(*itr_c));
1
  • This answer is completely irrelevant to the question
    – 0101
    Sep 17, 2023 at 0:06
0

As the answer here is completely irrelevant to the question. I am adding an answer that actually resolves the problem.

What's needed in this case is an extra parameter referring to the contract's name. As follows:

struct [[eosio::table, eosio::contract("helloworld")]] testtable_j {}

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.