How can I force compiler to use default constructor when adding element to vector using emplace_back?
enum E {E1, E2};
struct A
{
A(){}
A(int i){}
};
void main()
{
std::vector<std::pair<E, A>> testMap;
testMap.emplace_back(E1, 10);
// testMap.emplace_back(E2);
}
Commented out line gives following error: error C2664: 'std::pair<_Ty1,_Ty2>::pair(const std::pair<_Ty1,_Ty2> &)' : cannot convert parameter 1 from 'E' to 'const std::pair<_Ty1,_Ty2> &'
Aucun commentaire:
Enregistrer un commentaire