modifying for loop from map of integers to vector

This is a discussion on modifying for loop from map of integers to vector within the C++ Programming forums, part of the General Programming Boards category; So I have a function written as follows Code: inline tSomething::tSomething(map<int, tSomethingElse* > const & Points, tWhatever const * a_ptr, ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    59

    modifying for loop from map of integers to vector

    So I have a function written as follows

    Code:
    inline
    tSomething::tSomething(map<int, tSomethingElse* > const & Points, 
                         tWhatever const * a_ptr,
                         int ID,
                 vector<vector<int> > const & one,
                 vector<bool> const & two,
                 vector<int> const & three):
     _ID(ID),_a_ptr(a_ptr),_points(Points),_one(one),_two(two),_three(three)
    {
      for (map<int,tSomethingElse*>::const_iterator it = _points.begin(); it != _points.end(); it++)
      _stamp.push_back(it->first);
      sort(_stamp.begin(),_stamp.end());
      Target();
    }
    and now I have to take

    Code:
    inline
    tSomething::tSomething(std::vector<tSomething::tSomethingElse*, std::allocator<tSomething::tSomethingElse*> >& Points,
                         tWhatever const * a_ptr,
     _a_ptr(a_ptr),_points(Points)
    and write a for loop that does the same thing, so...

    Code:
    {
      for (???)
      _stamp.push_back(it->first);
      sort(_stamp.begin(),_stamp.end());
      Target();
    }
    but I am having trouble adapting the code. Is it straightforward or not really possible with the change of format?

    Thanks in advance

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    You can't. You are missing data. In the first example, you got pairs of points and ints, storing the ints. Now your get a list of points. There's not way you can store the ints aside from making them up on the fly. You didn't get them.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 10-01-2012, 09:00 AM
  2. Replies: 2
    Last Post: 09-25-2012, 11:54 PM
  3. Using Loop Commands and odd integers
    By Sammy2011 in forum C++ Programming
    Replies: 11
    Last Post: 10-06-2011, 10:09 AM
  4. Replies: 5
    Last Post: 11-12-2009, 10:16 AM
  5. Modifying a while loop
    By Suchy in forum C++ Programming
    Replies: 1
    Last Post: 09-12-2006, 12:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21