samedi 24 décembre 2016

`std::vector.emplace_back` ignores standard constructor

I can't get vector.emplace_back to work. It doesn't handle the constructor on my SNV struct.

#include <stdexcept>
#include <vector>

struct SNV {

    char ref;
    float p_a;
    float p_c;
    float p_g;
    float p_t;

    SNV(char ref, float p_a, float p_c, float p_g, float p_t)
    : ref(ref), p_a(p_a), p_c(p_c), p_g(p_g), p_t(p_t)
    {}

};

Later on in another class I initialise a vector of some specified length, e.g.

std::vector<SNV> snvs(100);

Then I try to emplace a struct:

snvs.emplace_back(ref, p_a, p_c, p_g, p_t);

On compilation I get this:

./mapping.h:14:8: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 0 were provided
./mapping.h:22:5: note: candidate constructor not viable: requires 5 arguments, but 0 were provided
    SNV(char ref, float p_a, float p_c, float p_g, float p_t)

Aucun commentaire:

Enregistrer un commentaire