Container pointer

Discussion in 'C++' started by Isliguezze, May 24, 2009.

  1. Isliguezze

    Isliguezze Guest

    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...
     
    Isliguezze, May 24, 2009
    #1
    1. Advertising

  2. Isliguezze

    SG Guest

    On 24 Mai, 14:53, Isliguezze <> 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::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
     
    SG, May 24, 2009
    #2
    1. Advertising

  3. Isliguezze

    Isliguezze Guest

    Right! Thanks.
    P.S. Sorry for being so stupid.
     
    Isliguezze, May 25, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vivi Orunitia
    Replies:
    11
    Views:
    4,481
    Martijn Lievaart
    Feb 4, 2004
  2. Maitre Bart
    Replies:
    2
    Views:
    527
    Maitre Bart
    Feb 11, 2004
  3. Steven T. Hatton
    Replies:
    4
    Views:
    3,908
    Rob Williscroft
    Dec 5, 2004
  4. Replies:
    4
    Views:
    805
    Daniel T.
    Feb 16, 2006
  5. wolverine
    Replies:
    2
    Views:
    454
    Marcus Kwok
    Jul 24, 2006
Loading...

Share This Page