mercredi 14 novembre 2018

C++ how to use emplace_back for user defined structure

I am trying to make use of emplace_back for my user defined structure:

#include <cstdint>
#include <vector>
#include <string>

enum class Fmt : std::uint8_t
{
    FMT_NONE

};


enum class FType : std::uint8_t
{
    FD_NONE
};

enum class RWProp : std::uint8_t
{
    PROP_RO
};


enum class TTypes : std::uint8_t
{

    TYPE_NONE 
};

struct ID
{
    ID(std::initializer_list<int> _id_) : id(_id_){}
    std::vector<int> id;
};

struct FId
{
    FId(uint32_t id): uid(id), types(TTypes::TYPE_NONE) {}
    FId(uint32_t id, TTypes ty) : uid(id), types(ty) {}
    FId(const FId& fid) : uid(fid.uid), types(fid.types) {}
    uint32_t uid; 
    TTypes types; 
};


struct EntryDef
{
    EntryDef(std::initializer_list<int> id, FType ft, Fmt mt, RWProp rw, FId f_id) : mid(id),
        ftype(ft), rfmt(mt),mrw(rw), fid(f_id) {}
    ID mid;
    FType ftype;
    Fmt rfmt;
    RWProp mrw;
    FId fid;
};

struct Def
{
    std::vector<EntryDef> ent;
};

int main()

{
 Def a;
 a.ent.emplace_back({ {2}, 1 }, FType::FD_NONE, Fmt::FMT_NONE, RWProp::PROP_RO, FId(0,TTypes::TYPE_NONE));
}

I get compilation issues:

$ c++ -std=c++11 try60.cpp
try60.cpp: In function 'int main()':
try60.cpp:66:105: error: no matching function for call to 'std::vector<EntryDef>::emplace_back(<brace-enclosed initializer list>, FType, Fmt, RWProp, FId)'
  a.ent.emplace_back({ {2}, 1 }, FType::FD_NONE, Fmt::FMT_NONE, RWProp::PROP_RO, FId(0,TTypes::TYPE_NONE));
                                                                                                         ^
try60.cpp:66:105: note: candidate is:
In file included from C:/tools/mingw64/x86_64-w64-mingw32/include/c++/vector:69:0,
                 from try60.cpp:2:
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/bits/vector.tcc:91:7: note: void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {}; _Tp = EntryDef; _Alloc = std::allocator<EntryDef>]
       vector<_Tp, _Alloc>::
       ^
C:/tools/mingw64/x86_64-w64-mingw32/include/c++/bits/vector.tcc:91:7: note:   candidate expects 0 arguments, 5 provided

I tried my ways out but could not resolve the issue - what's the issue in my code?

Aucun commentaire:

Enregistrer un commentaire