Thread: how to copy a queu?

  1. #1
    Registered User
    Join Date
    May 2009
    Location
    kuwait
    Posts
    9

    how to copy a queu?

    hellow there .. i am new here and i do like this web
    actually i am a student and i need help with c++


    how can i copy a queue then using the assignment operatopr (=) in my code?
    i don`t need an algorithem i need functions please

    thanks alot

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Pretty easy, for some type T:
    Code:
    std::queue<T> queue1;
    // ...
    std::queue<T> queue2(queue1); // copy construction
    std::queue<T> queue3;
    queue3 = queue1; // copy assignment
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    Use a constructor:

    Code:
    std::queue<my_type> queue (other_queue);
    (Too late)

  4. #4
    Registered User
    Join Date
    May 2009
    Location
    kuwait
    Posts
    9
    so to copy a queue i should use a
    1)default constructor
    2)copy constructor

    then to use the = operatoer
    queue3 = queue1;

    as simple as that?

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    More like: prefer to use the copy constructor. But if you already have a queue, use the copy assignment operator.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    May 2009
    Location
    kuwait
    Posts
    9
    thanks alot laserlight ;*
    great chance to have u as a tutor

  7. #7
    Registered User
    Join Date
    May 2009
    Location
    kuwait
    Posts
    9
    thanks alot brafil ;**

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Gcc can't find obvious copy constructor
    By SevenThunders in forum C++ Programming
    Replies: 13
    Last Post: 03-19-2009, 02:41 PM
  2. copy = concatenate ?
    By Arruba in forum C Programming
    Replies: 3
    Last Post: 11-03-2006, 04:54 PM
  3. calling copy constructor from template
    By Ancient Dragon in forum C++ Programming
    Replies: 3
    Last Post: 09-28-2005, 01:54 PM
  4. dynamic memory alloccation & returning objects
    By haditya in forum C++ Programming
    Replies: 8
    Last Post: 04-21-2005, 11:55 PM
  5. Copy Constructor Help
    By Jubba in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 11:15 AM