Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

No matching constructor for initialization AddressBook example #6015

Closed
stone89son opened this issue Oct 16, 2018 · 2 comments
Closed

No matching constructor for initialization AddressBook example #6015

stone89son opened this issue Oct 16, 2018 · 2 comments

Comments

@stone89son
Copy link

stone89son commented Oct 16, 2018

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

@bagaking
Copy link

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

@stone89son
Copy link
Author

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

Thank you very much.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants