lundi 4 novembre 2019

How to access elements of vector of pairs using a pointer?

I am creating a vector of int pairs to create 28 domino pieces. After creating a piece, how do I access it using the pointer? I tried x->first, x[0]->first, x.first. I seem to be misunderstanding something. Here is the code, for example, how would I access the first element in the pair I just created.

vector < pair <int, int>>* x;

x = new vector<pair <int, int>>;

x->push_back(make_pair(1, 3));

Aucun commentaire:

Enregistrer un commentaire