0

I'm unable to compile a small test contract and am hoping for guidance. I have a class called Account, in the following 2 files:

// --- account.hpp 
#pragma once

#include <string>
#include <cmath>
#include <limits>
#include <numeric>
#include <eosio/eosio.hpp>
#include <eosio/system.hpp>
#include <eosio/asset.hpp>
#include <eosio/singleton.hpp>
#include <eosio/transaction.hpp>

namespace myapp {
    using namespace eosio;

    class Account {
        private:

        struct [[eosio::table]] _balances {
            asset value;
            uint64_t primary_key() const {
                return value.symbol.code().raw();
            }   
        };  
        typedef multi_index<name("balances"), _balances> EOST;
        EOST t;

        public:

        class Balance {
            public:

            Balance(EOST t, symbol sym);
            int64_t sat = 0;
            double amt = 0;
        };  

        Account(name code, name acct);
        Balance bal(asset o); 
        Balance bal(symbol sym);
    };  
}

and

// --- account.cpp
#include "account.hpp"

namespace myapp {
    using namespace eosio;
    Account::Balance::Balance(EOST t, symbol sym) {
        auto o = t.find(sym.code().raw());
        if (o != t.end()) {
            sat = o->value.amount;
            amt = o->value.amount / pow(10, o->value.symbol.precision());
        }
    }
    Account::Account(name code, name acct)
        : t(code, acct.value) {
    }
    Account::Balance Account::bal(asset o) {
        return bal(o.symbol);
    }   
    Account::Balance Account::bal(symbol sym) {
        return Balance(this->t, sym);
    }       
}

which I then use from my contract quite simply like this:

// --- token.cpp
#pragma once

#include <string>
#include <cmath>
#include <limits>
#include <numeric>
#include <eosio/eosio.hpp>
#include <eosio/system.hpp>
#include <eosio/asset.hpp>
#include <eosio/singleton.hpp>
#include <eosio/transaction.hpp>

#include "account.cpp"

namespace eosiosystem {
    class system_contract;
}

namespace eosio {
    class [[eosio::contract("token")]] token : public contract {
    public:
        [[eosio::action]] void ping() {
            myapp::Account acct(_self, name("cust1"));
            myapp::Account::Balance b = acct.bal(symbol("USD", 8));
            print("\nbalance = ", b.sat, ", ", b.amt);
        }   
    };  
}

however, the code won't compile, citing the aforementioned error:

In file included from /Users/ekkis/dev/eos/account/token.cpp:3: In file included from /usr/local/Cellar/eosio.cdt/1.6.1/opt/eosio.cdt/bin/../include/libcxx/string:470: In file included from /usr/local/Cellar/eosio.cdt/1.6.1/opt/eosio.cdt/bin/../include/libcxx/string_view:169: In file included from /usr/local/Cellar/eosio.cdt/1.6.1/opt/eosio.cdt/bin/../include/libcxx/__string:56: In file included from /usr/local/Cellar/eosio.cdt/1.6.1/opt/eosio.cdt/bin/../include/libcxx/algorithm:643: /usr/local/Cellar/eosio.cdt/1.6.1/opt/eosio.cdt/bin/../include/libcxx/memory:1759:31: error: call to implicitly-deleted copy constructor of 'eosio::multi_index<4152997948076064768, myapp::Account::_balances>::item_ptr' ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/local/Cellar/eosio.cdt/1.6.1/opt/eosio.cdt/bin/../include/libcxx/memory:1670:18: note: in instantiation of function template specialization 'std::__1::allocator::item_ptr>::construct::item_ptr, eosio::multi_index<4152997948076064768, myapp::Account::_balances>::item_ptr &>' requested here {__a.construct(__p, _VSTD::forward<_Args>(__args)...);} ^ /usr/local/Cellar/eosio.cdt/1.6.1/opt/eosio.cdt/bin/../include/libcxx/memory:1516:14: note: in instantiation of function template specialization 'std::__1::allocator_traits::item_ptr>

::__construct::item_ptr, eosio::multi_index<4152997948076064768, myapp::Account::_balances>::item_ptr &>' requested here {__construct(__has_construct(), ^ /usr/local/Cellar/eosio.cdt/1.6.1/opt/eosio.cdt/bin/../include/libcxx/memory:1600:17: note: in instantiation of function template specialization 'std::__1::allocator_traits::item_ptr> ::construct::item_ptr, eosio::multi_index<4152997948076064768, myapp::Account::_balances>::item_ptr &>' requested here construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1); ^ /usr/local/Cellar/eosio.cdt/1.6.1/opt/eosio.cdt/bin/../include/libcxx/vector:1030:21: note: in instantiation of function template specialization 'std::__1::allocator_traits::item_ptr> ::__construct_range_forward::item_ptr *, eosio::multi_index<4152997948076064768, myapp::Account::_balances>::item_ptr *>' requested here __alloc_traits::__construct_range_forward(__a, __first, __last, this... ^ /usr/local/Cellar/eosio.cdt/1.6.1/opt/eosio.cdt/bin/../include/libcxx/vector:1213:9: note: in instantiation of function template specialization 'std::__1::vector::item_ptr, std::__1::allocator::item_ptr> ::__construct_at_end::item_ptr *>' requested here __construct_at_end(__x.__begin_, __x.__end_, __n); ^ /usr/local/Cellar/eosio.cdt/1.6.1/opt/eosio.cdt/bin/../include/eosiolib/contracts/eosio/multi_index.hpp:431:7: note: in instantiation of member function 'std::__1::vector::item_ptr, std::__1::allocator::item_ptr> >::vector' requested here class multi_index ^ /usr/local/Cellar/eosio.cdt/1.6.1/opt/eosio.cdt/bin/../include/eosiolib/contracts/eosio/multi_index.hpp:474:32: note: copy constructor of 'item_ptr' is implicitly deleted because field '_item' has a deleted copy constructor std::unique_ptr _item; ^ /usr/local/Cellar/eosio.cdt/1.6.1/opt/eosio.cdt/bin/../include/libcxx/memory:2388:3: note: copy constructor is implicitly deleted because 'unique_ptr::item, std::__1::default_delete::item> >' has a user-declared move constructor unique_ptr(unique_ptr&& __u) noexcept ^ Warning, empty ricardian clause file Warning, empty ricardian clause file Warning, action does not have a ricardian contract 1 error generated. Error while processing /Users/ekkis/dev/eos/account/token.cpp. abigen error

from which the error copy constructor of 'item_ptr' is implicitly deleted because field '_item' has a deleted copy constructor std::unique_ptr _item stands out. but I'm no brighter for it as to what the issue could be

help?

1 Answer 1

0

ah. the problem is that the EOS table must be passed by reference:

Account::Balance::Balance(EOST &t, symbol sym) {

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.