Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Container pointer

Reply
Thread Tools

Container pointer

 
 
Isliguezze
Guest
Posts: n/a
 
      05-24-2009
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:air<int, int> > q, w;
std::queue<std:air<int, int> > *p;

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

//...
p->push(smth), etc...
 
Reply With Quote
 
 
 
 
SG
Guest
Posts: n/a
 
      05-24-2009
On 24 Mai, 14:53, Isliguezze <(E-Mail Removed)> wrote:
> 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:air<int, int> > q, w;
> std::queue<std:air<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
 
Reply With Quote
 
 
 
 
Isliguezze
Guest
Posts: n/a
 
      05-25-2009
Right! Thanks.
P.S. Sorry for being so stupid.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
container inside container in stl wolverine C++ 2 07-24-2006 03:08 PM
Copy elements from one STL container to another STL container Marko.Cain.23@gmail.com C++ 4 02-16-2006 05:03 PM
std::transform container => std::abs(container) Steven T. Hatton C++ 4 12-05-2004 07:10 AM
STL: container's values setup by another container Maitre Bart C++ 2 02-11-2004 12:11 AM
std::container::iterator vs std::container::pointer Vivi Orunitia C++ 11 02-04-2004 08:09 AM



Advertisments