Container pointer

I

Isliguezze

I need to use one of two std::queue objects and to change current if
needed. How do I perform this in c++? I used this code:

std::queue<std::pair<int, int> > q, w;
std::queue<std::pair<int, int> > *p;

if (/*smth*/) p = q;
else p = w;

//...
p->push(smth), etc...
 
S

SG

I need to use one of two std::queue objects and to change current if
needed. How do I perform this in c++? I used this code:

std::queue<std::pair<int, int> > q, w;
std::queue<std::pair<int, int> > *p;

if (/*smth*/)  p = q;
else           p = w;

//...
p->push(smth), etc...

Please post a short but complete example that is supposed to compile.
Also you need to state your problem.

The rather obvious mistake here is that the assignments can't be
correct. p is a pointer and you need to take the address of q and w.

p = &q;
p = &w;

Cheers!
SG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,886
Members
47,419
Latest member
ArturoBres

Latest Threads

Top