2 Replies - 696 Views - Last Post: 15 May 2010 - 01:29 PM Rate Topic: -----

#1 Guest_willlison*


accessing values in a Map container

Posted 15 May 2010 - 10:56 AM

I have a map table which was created and populated, I then trasfered the data as strings(sstream) to another class.So in the next class, I can only access the keys.how do I get access to other values so that I can compare them.
//Values in the map table
Bid* bidA= new Bid;
         bidA->bidId = i;
         bidA->bidType = 'A';
         bidA->traderId = trd;
         bidA->quantity = rand() % (MAXQUANTITY - MINQUANTITY + 1 ) + MINQUANTITY ;
         bidA->price = rand() % (MAXPRICE - MINPRICE + 1) + MINPRICE;

The two containers created on the other side that need comparions.I can display their data, but access to the values they point to is my problem.

cout<<"These are the Sellers bids\n\n";
                 map<int, Bid*> sellers(bidtable);
                 sellers.erase(15);sellers.erase(16); sellers.erase(17);sellers.erase(18);sellers.erase(19);
                 for(iter=sellers.begin(); iter != sellers.end(); iter++)
                 cout << iter->second->toString() << endl<<"\n";
                 // Creating another map for the sellers.
                 cout<<"These are the Buyers bids\n\n";
                 map<int, Bid*> buyers(bidtable);
                 buyers.erase(6);buyers.erase(7); buyers.erase(8);buyers.erase(9);
                 for(iter=buyers.begin(); iter != buyers.end(); iter++)

Is This A Good Question/Topic? 0

Replies To: accessing values in a Map container

#2 eker676   User is offline

  • Software Engineer
  • member icon

Reputation: 379
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: accessing values in a Map container

Posted 15 May 2010 - 11:06 AM

It looks like you already have access to the values not the keys. You can use and iterator to get at the keys and values.




*Edit* if you need access to the keys or values then you could declare the classes as "friend"s so the classes can access each others private/protected data.

This post has been edited by eker676: 15 May 2010 - 11:08 AM

Was This Post Helpful? 0
  • +
  • -

#3 Guest_Guest*


Re: accessing values in a Map container

Posted 15 May 2010 - 01:29 PM

Can you please show me an example of how I can compare for example two prices in the two containers.

I did try it like so, but didnt seem to work.
bool compareBidList(bidtable one, bidtable two) { 
for(iter=bidtable.begin(); iter != bidtable.end(); iter++
        if (bidtable.type == 'A' && bidtable.type == 'B') 
                return (bidtable one.price < bidtabletwo.price); 
        return false; 

Was This Post Helpful? 0

Page 1 of 1