I am trying to make use of emplace_back for my user defined structure:
#include <cstdint>
#include <vector>
#include <string>
struct IDNumber
{
IDNumber(std::vector<int> d) : id(d){}
std::vector<int> id;
};
struct Def
{
Def(std::initializer_list<int> id) : mid(id){}
IDNumber mid;
};
struct Student
{
std::vector<Def> ent;
};
int main()
{
Student a;
a.ent.emplace_back({ {2000} });
}
I get compilation issues:
error: no matching function for call to 'std::vector<EntryDef>::emplace_back'
std::initializer_list<int>
yet you pass{ {2}, 1 }
?emplace_back
is function template which tries to deduce the types of arguments. an initializer list does not have a type, so deduction fails. Usestd::initializer_list<int>{ 2, 1 }
.initializer_list