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;
}