@Zerp, I try to use the http://ift.tt/1BQQqUj descrbing way to traverse all elements of the same map, but I met some compile error of '=',
error 1 error C2679: binary “=”: not find “std::_List_iterator<std::_List_val<std::_List_simple_types<std::pair<const _Kty,_Ty>>>>”
Code:
#include <iostream>
#include <string>
#include <memory>
#include <map>
#include <unordered_map>
using namespace std;
class Instrument{
public:
virtual void display() = 0;
virtual ~Instrument(){};
};
class Stock :
public Instrument{
public:
Stock(){
cout << "This is stock, please input its information: ";
cin >> name >> bidPrice >> askPrice >> lastPrice >> issueExchange;
}
virtual void display(){
cout << "This is to display stock: " << name << " "
<< bidPrice << " "
<< askPrice << " "
<< lastPrice << " "
<< issueExchange << " "
<< endl;
}
virtual ~Stock(){}
inline string getname(){
return name;
}
private:
string name;
double bidPrice;
double askPrice;
double lastPrice;
int issueExchange;
};
class Option :
public Instrument{
public:
Option(){
cout << "This is option, please input its information: ";
cin >> name >> uname >> bidPrice >> askPrice >> lastPrice >> contractSize >> exp;
}
virtual void display(){
cout << "This is to display option: "
<< name << " "
<< uname << " "
<< bidPrice << " "
<< askPrice << " "
<< lastPrice << " "
<< contractSize << " "
<< exp << " "
<< endl;
}
virtual ~Option(){}
inline string getuname(){
return uname;
}
private:
string name;
string uname;
double bidPrice;
double askPrice;
double lastPrice;
int contractSize;
double exp;
};
int main(){
int N = 2; int i = 5;
// Construct the Stock, Option maps
map<int, Stock> myStockMap;
for (i = 0; i < N; i++) myStockMap.insert(pair<const int, Stock>(i, Stock()));
for (map<int, Stock>::iterator it = myStockMap.begin(); it != myStockMap.end(); it++){
it->second.display();
}
unordered_multimap<string, Option> myOptionMultiMap;
for (i = 0; i < N; i++){
Option a = Option();
myOptionMultiMap.insert(pair<string, Option>(a.getuname(), a));
}
for (auto it = myOptionMultiMap.begin(); it != myOptionMultiMap.end(); ++it)
it->second.display();
pair < unordered_map<string, Option>::iterator,
unordered_map<string, Option>::iterator > ret;
for (auto it = myStockMap.begin(); it != myStockMap.end(); it++){
it->second.display();
ret = myOptionMultiMap.equal_range(it->second.getname());
while (ret.first != ret.second){// there is some problem
cout << "\t";
(ret.first++)->second.display();
}
}
system("pause");
return 0;
}
Aucun commentaire:
Enregistrer un commentaire