Click here to Skip to main content
15,891,905 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: What's wrong in previous location of an object ? Pin
David Crow19-Jan-12 4:09
David Crow19-Jan-12 4:09 
Questionhow to maintain previous location of an object using maps in c++ ? Pin
love bird19-Jan-12 1:15
love bird19-Jan-12 1:15 
QuestionRe: how to maintain previous location of an object using maps in c++ ? Pin
CPallini19-Jan-12 1:47
mveCPallini19-Jan-12 1:47 
QuestionHow can i store object current and previous location as an id of object ? Pin
love bird18-Jan-12 19:36
love bird18-Jan-12 19:36 
AnswerRe: How can i store object current and previous location as an id of object ? Pin
«_Superman_»18-Jan-12 19:44
professional«_Superman_»18-Jan-12 19:44 
GeneralRe: How can i store object current and previous location as an id of object ? Pin
love bird18-Jan-12 20:54
love bird18-Jan-12 20:54 
GeneralRe: How can i store object current and previous location as an id of object ? Pin
«_Superman_»18-Jan-12 21:05
professional«_Superman_»18-Jan-12 21:05 
GeneralRe: How can i store object current and previous location as an id of object ? Pin
CPallini18-Jan-12 22:17
mveCPallini18-Jan-12 22:17 
Change this way to have something 'compiler-friendly':
C++
#include <iostream>
#include <map>
#include "vector"
using namespace std;
int main()
{ 
  int x   = 5;
  int y = 10;
  cout<< "Hello " <<endl;

  std::vector<std::pair<int , int>> ids;
  ids.push_back(std::make_pair(x,y));
  for( std::vector<std::pair<int , int>>::iterator it = ids.begin() ; 
    it != ids.end(); ++it)
  {
    cout<<"ids as " << it->first << ", " << it->second <<endl;
  }
}


However, if you need to record positions of some objects having different IDs, then you need a further indirection step, e.g.
C++
typedef std::vector< std::pair<int , int> > Pos;

vector <Pos> obj;

obj.push_back(Pos()); // object 0
obj[0].push_back( std::make_pair(5, 10) ); // first position
obj[0].push_back( std::make_pair(6, 12) ); // second position


obj.push_back(Pos()); // object 1
obj[1].push_back( std::make_pair(3, 7) ); // first position
obj[1].push_back( std::make_pair(-2, 9) ); // second position

for ( vector<Pos>::size_type  n = 0; n<obj.size(); n++)
{
  cout << "object " << n << " positions: " << endl;
  for ( Pos::size_type p = 0; p < obj[n].size(); p++)
  {
    cout << "pos[" << p << "] {" << obj[n][p].first << ", " << obj[n][p].second << "}" << endl;
  }
}

If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.

This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke

[My articles]

AnswerRe: How can i store object current and previous location as an id of object ? Pin
Richard MacCutchan18-Jan-12 21:38
mveRichard MacCutchan18-Jan-12 21:38 
QuestionBuilding for older Windows versions with VS 2010 Pin
John Buller18-Jan-12 4:31
John Buller18-Jan-12 4:31 
AnswerRe: Building for older Windows versions with VS 2010 Pin
Albert Holguin18-Jan-12 4:48
professionalAlbert Holguin18-Jan-12 4:48 
GeneralRe: Building for older Windows versions with VS 2010 Pin
John Buller18-Jan-12 8:58
John Buller18-Jan-12 8:58 
GeneralRe: Building for older Windows versions with VS 2010 Pin
Albert Holguin18-Jan-12 9:55
professionalAlbert Holguin18-Jan-12 9:55 
QuestionProfiling C++/QT Project in VS 2010 points to WinEventFilter() Pin
p-j-u-s-k-e17-Jan-12 23:48
p-j-u-s-k-e17-Jan-12 23:48 
QuestionHow UnRAR a rar file with password Pin
hack00417-Jan-12 19:43
hack00417-Jan-12 19:43 
AnswerRe: How UnRAR a rar file with password Pin
CPallini17-Jan-12 21:33
mveCPallini17-Jan-12 21:33 
GeneralRe: How UnRAR a rar file with password Pin
Mohibur Rashid17-Jan-12 22:26
professionalMohibur Rashid17-Jan-12 22:26 
GeneralRe: How UnRAR a rar file with password Pin
Richard MacCutchan17-Jan-12 23:03
mveRichard MacCutchan17-Jan-12 23:03 
GeneralRe: How UnRAR a rar file with password Pin
CPallini17-Jan-12 23:05
mveCPallini17-Jan-12 23:05 
GeneralRe: How UnRAR a rar file with password Pin
hack00417-Jan-12 23:39
hack00417-Jan-12 23:39 
GeneralRe: How UnRAR a rar file with password Pin
Richard MacCutchan18-Jan-12 0:02
mveRichard MacCutchan18-Jan-12 0:02 
GeneralRe: How UnRAR a rar file with password Pin
Rajesh R Subramanian18-Jan-12 2:09
professionalRajesh R Subramanian18-Jan-12 2:09 
GeneralRe: How UnRAR a rar file with password Pin
Richard MacCutchan18-Jan-12 2:16
mveRichard MacCutchan18-Jan-12 2:16 
GeneralRe: How UnRAR a rar file with password Pin
Rajesh R Subramanian18-Jan-12 2:26
professionalRajesh R Subramanian18-Jan-12 2:26 
GeneralRe: How UnRAR a rar file with password Pin
Rajesh R Subramanian18-Jan-12 2:11
professionalRajesh R Subramanian18-Jan-12 2:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.