Help with std::map

Hi, everyone. I need your help... I wanted to fill an std::map with some value_type arguments. When I run my code, the following error occured. Can anyone tell me how to fix it? Thanks!

error C2664: 'std::pair<_Ty1,_Ty2>::pair(const unsigned int &,const _Ty2 &)' : cannot convert parameter 2 from 'std::pair<_Ty1,_Ty2>' to 'const



1
2
3
4
5
6
7
8
9
10
11
12
typedef boost::numeric::ublas::vector<double> BVector;
typedef std::map<unsigned int,std::pair<unsigned int, std::vector<BVector>>> MyMap;

using namespace std;
using boost::numeric::ublas::zero_vector;

unsigned int iMaxLevel(1000);
vector<BVector> mean_var(iMaxLevel,zero_vector<double>(2)); 
vector<unsigned int> vn(iMaxLevel);
MyMap mapRes;
for(unsigned int i=0; i<iMaxLevel; ++i)
   mapRes.emplace(i,make_pair(vn[i],mean_var[i])); // error urcurs in this line 
Last edited on
make_pair(vn[i],mean_var[i]) gives you a std::pair<unsigned int, BVector>.
The value type of MyMap is std::pair<unsigned int, std::vector<BVector>>.
See the difference?
why? I used the map::emplace() function...
 
mapRes.emplace(i,make_pair(vn[i],mean_var[i]));
Maybe you got the MyMap typedef wrong. Should it be
 
typedef std::map<unsigned int,std::pair<unsigned int, BVector>> MyMap;
?
The type definition of MyMap is what I want. It is a vector of BVectors. For example, mean_var is a vector containing the statistics of mean_var.size() sets of samples.
I've been stuck with this problem for 6 hours...
Last edited on
Do you want all map elements to contain all the sets of samples? In that case you should remove the second [i] from line 12.
 
mapRes.emplace(i,make_pair(vn[i],mean_var));

Is this really what you want?
Last edited on
Maybe there is some confusion here:
Xuan Liu wrote:
The type definition of MyMap is what I want. It is a vector of BVectors. For example, mean_var is a vector ...

MyMap is not a vector. It is a map.

It is true what you say about mean_var but MyMap is something else.
Yes, you're right. Thank you!!!
Topic archived. No new replies allowed.