Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MCF question

MCF question

Scheduled Pinned Locked Moved C / C++ / MFC
c++questiongraphicstutorial
14 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Anderson Jogie

    Do anyone know how to convert a vector to a list in Visual C++? I tried casting, it does not work for me.

    M Offline
    M Offline
    Maximilien
    wrote on last edited by
    #2

    Are you talking about a std::vector and a std::list ? Don't think there is a direct conversion, you will need to copy from one to the other.

    This signature was proudly tested on animals.

    A 1 Reply Last reply
    0
    • M Maximilien

      Are you talking about a std::vector and a std::list ? Don't think there is a direct conversion, you will need to copy from one to the other.

      This signature was proudly tested on animals.

      A Offline
      A Offline
      Anderson Jogie
      wrote on last edited by
      #3

      Yes : std::vector to std::list What is the best method to copy the data? Can you give an example? Thanks.

      M D D 3 Replies Last reply
      0
      • A Anderson Jogie

        Yes : std::vector to std::list What is the best method to copy the data? Can you give an example? Thanks.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #4

        It's not MFC, but something like:

        vector<int> vec;
        vector<int>::iterator it;
        list<int> l;

        for (it = vec.begin(); it != vec.end(); it++)
        l.push_back(*it);

        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        A 1 Reply Last reply
        0
        • A Anderson Jogie

          Yes : std::vector to std::list What is the best method to copy the data? Can you give an example? Thanks.

          M Offline
          M Offline
          Maximilien
          wrote on last edited by
          #5

          I'm not an STL expert, but after a quick google (bing did not give valid answers in the first few pages), here are a couple of solutions (adapt to your particular situation)

          std::copy (v.begin (), v.end (), std::back_inserter (l))

          or

          std::list<int> l(v.begin(), v.end());

          or ...

          This signature was proudly tested on animals.

          J 1 Reply Last reply
          0
          • A Anderson Jogie

            Yes : std::vector to std::list What is the best method to copy the data? Can you give an example? Thanks.

            D Offline
            D Offline
            Dustin Henry
            wrote on last edited by
            #6

            Just so you know, std::vector and std::list have nothing to do with MFC. They are part of STL or Standard Template Library and are cross platform.

            1 Reply Last reply
            0
            • D David Crow

              It's not MFC, but something like:

              vector<int> vec;
              vector<int>::iterator it;
              list<int> l;

              for (it = vec.begin(); it != vec.end(); it++)
              l.push_back(*it);

              "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              A Offline
              A Offline
              Anderson Jogie
              wrote on last edited by
              #7

              I forget to mention it's two different data types see code below: std::list TempRes; TempRes.clear; std::vector::iterator it; for (it = TempResList.begin(); it != TempResList.end(); it++) TempRes.push_back(*it); Thanks the help on this.

              A 1 Reply Last reply
              0
              • A Anderson Jogie

                I forget to mention it's two different data types see code below: std::list TempRes; TempRes.clear; std::vector::iterator it; for (it = TempResList.begin(); it != TempResList.end(); it++) TempRes.push_back(*it); Thanks the help on this.

                A Offline
                A Offline
                Anderson Jogie
                wrote on last edited by
                #8

                Well I guess it did not compile fully earlier, I am still getting the compiler error message below when I tried to copied the data from a vector to a list. ompiling... FSSCHED.CPP c:\program files\ilps\code\fstool\fssched.cpp(1165) : error C2664: 'push_back' : cannot convert parameter 1 from 'class RDLTemporaryResource *' to 'class RDLResource *const & ' Reason: cannot convert from 'class RDLTemporaryResource *' to 'class RDLResource *const ' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe. fstool.dll - 1 error(s), 0 warning(s)

                D 1 Reply Last reply
                0
                • A Anderson Jogie

                  Well I guess it did not compile fully earlier, I am still getting the compiler error message below when I tried to copied the data from a vector to a list. ompiling... FSSCHED.CPP c:\program files\ilps\code\fstool\fssched.cpp(1165) : error C2664: 'push_back' : cannot convert parameter 1 from 'class RDLTemporaryResource *' to 'class RDLResource *const & ' Reason: cannot convert from 'class RDLTemporaryResource *' to 'class RDLResource *const ' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Error executing cl.exe. fstool.dll - 1 error(s), 0 warning(s)

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #9

                  That's because your list is for RDLResource* objects while your iterator for that list is for RDLTemporaryResource* objects.

                  "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  A 1 Reply Last reply
                  0
                  • D David Crow

                    That's because your list is for RDLResource* objects while your iterator for that list is for RDLTemporaryResource* objects.

                    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    A Offline
                    A Offline
                    Anderson Jogie
                    wrote on last edited by
                    #10

                    Right. So I am having problems transferring the data from the vector to the list. How do I work around doing that in my case? I tied casting, it compiled but the application crashes at runtime. Thanks.

                    D 1 Reply Last reply
                    0
                    • A Anderson Jogie

                      Right. So I am having problems transferring the data from the vector to the list. How do I work around doing that in my case? I tied casting, it compiled but the application crashes at runtime. Thanks.

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #11

                      Anderson Jogie wrote:

                      How do I work around doing that in my case?

                      That's impossible to tell since I know nothing of either of those two classes. For example, how would you copy a vector of Automobile objects to a list of Animal objects?

                      Anderson Jogie wrote:

                      I tied casting, it compiled but the application crashes at runtime.

                      That would not work unless the two classes had a "is a" relationship.

                      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                      J 1 Reply Last reply
                      0
                      • D David Crow

                        Anderson Jogie wrote:

                        How do I work around doing that in my case?

                        That's impossible to tell since I know nothing of either of those two classes. For example, how would you copy a vector of Automobile objects to a list of Animal objects?

                        Anderson Jogie wrote:

                        I tied casting, it compiled but the application crashes at runtime.

                        That would not work unless the two classes had a "is a" relationship.

                        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        J Offline
                        J Offline
                        Jim Crafton
                        wrote on last edited by
                        #12

                        DavidCrow wrote:

                        That would not work unless the two classes had a "is a" relationship.

                        Reading that it occurred to me that a more casual (possibly less informed) reader might look at that, pause, and then have their head explode. :)

                        ¡El diablo está en mis pantalones! ¡Mire, mire! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! Personal 3D projects Just Say No to Web 2 Point Oh

                        D 1 Reply Last reply
                        0
                        • M Maximilien

                          I'm not an STL expert, but after a quick google (bing did not give valid answers in the first few pages), here are a couple of solutions (adapt to your particular situation)

                          std::copy (v.begin (), v.end (), std::back_inserter (l))

                          or

                          std::list<int> l(v.begin(), v.end());

                          or ...

                          This signature was proudly tested on animals.

                          J Offline
                          J Offline
                          Jim Crafton
                          wrote on last edited by
                          #13

                          So you binged it, but it bonged out?

                          ¡El diablo está en mis pantalones! ¡Mire, mire! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! Personal 3D projects Just Say No to Web 2 Point Oh

                          1 Reply Last reply
                          0
                          • J Jim Crafton

                            DavidCrow wrote:

                            That would not work unless the two classes had a "is a" relationship.

                            Reading that it occurred to me that a more casual (possibly less informed) reader might look at that, pause, and then have their head explode. :)

                            ¡El diablo está en mis pantalones! ¡Mire, mire! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! Personal 3D projects Just Say No to Web 2 Point Oh

                            D Offline
                            D Offline
                            David Crow
                            wrote on last edited by
                            #14

                            I agree. :doh:

                            "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups