mercredi 1 janvier 2020

What is the emplace_back behaviour? [duplicate]

This question already has an answer here:

Given this

    vector<pair<int,int>> v;
    int k=0;
    v.emplace_back(k, ++k);
    v.emplace_back(k, k++);
    cout << v[0].first << "," << v[0].second << endl;
    cout << v[1].first << "," << v[1].second << endl;

Output is

1,1
2,1

I'd have expected to behave like a function call:

0,1
1,1

Anyone can explain what's going on?

Aucun commentaire:

Enregistrer un commentaire