I am passing a vector of bids from Trader class to Simulator class.which class then passes it on to the auctioneer class.something seems messed up, can anyone spot it please.
Below is part of the code: Error: 199 expected primary-expression before '&' token
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <iomanip>
using namespace std;
const int NUMSELLER = 1;
const int NUMBUYER = 1;
const int NUMBIDS = 20;
const int MINQUANTITY = 1;
const int MAXQUANTITY = 30;
const int MINPRICE =100;
const int MAXPRICE = 150;
int s=0;
int trdId;
// Bid, simple container for values
struct Bid {
int bidId, trdId, qty, price;
char type;
// for sort and find.
bool operator<(const Bid &other) const { return price < other.price; }
bool operator==(int bidId) const { return this->bidId == bidId; }
};
// alias to the list, make type consistent
typedef vector<Bid> BidList;
// this class generates bids!
class Trader {
private:
int nextBidId;
public:
Trader();
Bid getNextBid();
Bid getNextBid(char type);
void loadRange(BidList &, int size); // generate a number of bids
void loadRange(BidList &, char type, int size);
void submitBids();
};
Trader::Trader() : nextBidId(1) {}
#define RAND_RANGE(min, max) ((rand() % (max-min+1)) + min)
Bid Trader::getNextBid() {
char type = RAND_RANGE('A','B');
return getNextBid(type);
}
Bid Trader::getNextBid(char type) {
for(int i = 0; i < NUMSELLER+NUMBUYER; i++)
{
if (s<10){trdId=0;type='A';}
else {trdId=1;type='B';}
s++;
int qty = RAND_RANGE(MINQUANTITY, MAXQUANTITY);
int price = RAND_RANGE(MINPRICE, MAXPRICE);
Bid bid = {nextBidId++, trdId, qty, price, type};
return bid;
}
}
void Trader::loadRange(BidList &list, int size) {
for (int i=0; i<size; i++) { list.push_back(getNextBid()); }
}
void Trader::loadRange(BidList &list, char type, int size) {
for (int i=0; i<size; i++) { list.push_back(getNextBid(type)); }
}
bool compareBidList(Bid one, Bid two) {
if (one.type == 'A' && two.type == 'B')
return (one.price < two.price);
return false;
}
void sort(BidList &bidlist) { sort(bidlist.begin(), bidlist.end(), compareBidList); }
//-----------------------------------------------------------------
//To go through the bidlist (after sorting) in reverse direction.
//If the first entry found is an "A", ignore it
//Look for the first "A" to match it, and so on..........
//If "B" quantity is greater than the matching "A" quantity, copy the "A"
//To matchedBids, copy the "B" to matchedBids but with reduced quantity equal to the "A"
//REPLACE the "B" in the original vector with an NEW "B"
//---------------------------AUCTIONEER-------------------------------------------
class Auctioneer {
public:
Auctioneer (const BidList& vec); // copy constructor
typedef vector<Auctioneer> vec;
typedef vector<Auctioneer> buyers;
typedef vector<Auctioneer> sellers;
typedef Auctioneer* iterator;
typedef const Auctioneer* const_iterator;
//typedef size;
typedef Auctioneer value_type;
vector<Bid> list;
//typedef vector<Bid> BidList;
//typedef vector<Bid> iterator = BidList;
void accept_bids(vector<Bid> lst) {list = lst;}
void storeBids(){copy(list.begin(), list.end(),
bids.begin());}
void displayBids(){cout << "Ok the bids" << endl;} ;
void matchBid();
void calculateProfit();
vector<Auctioneer>::const_iterator b, e;
// new functions to return iterators
iterator begin() { return data; }
const_iterator begin() const { return data; }
iterator end() { return limit; }
const_iterator end() const { return limit; }
private:
string bids;
iterator data;
iterator limit;
};
//---------------------------------SIMULATOR-------------------------------------------
class Simulator {
Trader trader;
Auctioneer auctioneer;
//SmartTrader strader;
public:
vector<Bid> list;
char type;
void run();
};
void Simulator::run()
{
trader.loadRange(BidList &list); //calling from Base class
auctioneer.receiveBids(list);//receiver
auctioneer.displayBids; // print from receiver
}
//Simulator::accept_bids(bid_vector::const_iterator begin, bid_vector::const_iterator end))
int main() {
// Trader Trader;
// BidList bidlist;
Auctioneer auctioneer;
auctioneer.loadRange(bidlist, NUMBIDS);
show("Bids before sort:", bidlist);
sort(bidlist);
show("Bids after sort:", bidlist);
//count(bidlist);
//unpair(bidlist);
//unpair("Bids after sort:", bidlist);
searchTest(bidlist, 3);
searchTest(bidlist, 33);
system("pause");
return 0;
}