Hello guys,

My problem is that my code will automatically go through:

if((ask[i].getPrice()) <= (buy[j].getPrice())){

where ask and buy are vectors.

I need to know how I am suppose to compare them based upon the getPrice()......

Thanks in Advanced.

The rest of the code is here:

int i=(int)ask.size();
     int j=(int)buy.size();
 while(!buy.empty()){
              if((ask[i].getPrice()) <= (buy[j].getPrice())){//SUPPOSE to only allow through IF the prices are the same or less. BUT it goes straight through anyway...
                 matchedAsk.insert(matchedAsk.end(),ask.end(), ask.end()+1);
                 matchedBuy.insert(matchedBuy.end(),buy.end(), buy.end()+1);
                 ask.pop_back();
                 buy.pop_back();
                              
                   }else {
                 unmatchedAsk.insert(unmatchedAsk.end(),ask.end(),ask.end()+1);
                 ask.pop_back();
                 i--;
                 
                 }
                 }

Are you trying to compare the vectors as a whole? As in if (buy <= ask) ?

You have i and j initialized to size so you are actually pointing to one passed the end of the vector. Replace

int i=(int)ask.size();
     int j=(int)buy.size();

with

int i=(int)ask.size() - 1;
     int j=(int)buy.size() - 1;

Also with this line

matchedAsk.insert(matchedAsk.end(),ask.end(), ask.end()+1);

I belive you are using the iterators to insert the element of the vector into another container. But end() poins to one past the end of the vector so if you want to get the last element in the vector you would have to use

matchedAsk.insert(matchedAsk.end() - 1,ask.end() - 1, ask.end());
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.