Eos: No matching constructor for initialization AddressBook example

Created on 16 Oct 2018  路  2Comments  路  Source: EOSIO/eos

Dependencies:
EOSIO.CDT (Contract Development Toolkit) Version : 1.3.1

I learning in link https://developers.eos.io/eosio-home/docs/data-persistence but error:

I aslo read new version EOSIO.CDT 1.3.1 but, i cannot fix this error.

My code:

#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>

using namespace eosio;

CONTRACT addressbook : public eosio::contract {

 public:
    using contract::contract;

    addressbook(name self): contract(self) {}

   [[eosio::action]]
   void upsert(name user, std::string first_name, std::string 
   last_name, std::string street, std::string city, std::string state) 
   {
       require_auth( user );
       address_index addresses(_self, _self);
       auto iterator = addresses.find( user );
       if( iterator == addresses.end() )
       {
           addresses.emplace(user, [&]( auto& row ) {
           row.key = user;
           row.first_name = first_name;
           row.last_name = last_name;
           row.street = street;
           row.city = city;
           row.state = state;
        });
      }
    else 
    {
       std::string changes;
       addresses.modify(iterator, user, [&]( auto& row ) {
       row.key = user;
       row.first_name = first_name;
       row.last_name = last_name;
       row.street = street;
       row.city = city;
       row.state = state;
     });
   }
 }

[[eosio::action]]
void erase(name user){
   // require_auth(user);
    address_index addresses(_self, _self);
    auto iterator = addresses.find( user );
    eosio_assert(iterator != addresses.end(), "Record does not 
        exist");
    addresses.erase(iterator);
}

 private:
 struct [[eosio::table]] person {
       name key;
       std::string first_name;
       std::string last_name;
       std::string street;
       std::string city;
       std::string state;
       uint64_t primary_key() const { return key; }
  };
   typedef eosio::multi_index<"people"_n, person> address_index;

  };

EOSIO_DISPATCH( addressbook, (upsert)(erase) )

Error message:
Error 1: ./addressbook.cpp:12:30: error: no matching constructor for
initialization of 'eosio::contract'
addressbook(name self) : contract(self) {}

Error 2: address_index addresses(_self, _self);

Most helpful comment

Error 1: solution: you can just remove that.
Error 2: solution: use address_index addresses(_self, _self.value); instead.

All 2 comments

Error 1: solution: you can just remove that.
Error 2: solution: use address_index addresses(_self, _self.value); instead.

Error 1: solution: you can just remove that.
Error 2: solution: use address_index addresses(_self, _self.value); instead.

Thank you very much.

Was this page helpful?
0 / 5 - 0 ratings