I want to iterate over a map (pro_r) that has 3-tuples as keys. The map is an attribute of a struct called instance. When I try to initialize an iterator to the beginning of the map it gives me an error.
I tried doing the same with a locally defined map (hello) and it does not give me any error.
#include <iostream>
#include <utility> // std::pair, std::make_pair
#include <tuple> // std::pair, std::make_pair
#include <string> // std::string
#include <map>
using namespace std;
typedef tuple<int,int,int> tup3Int;
bool tup_comp (const tup3Int& lhs, const tup3Int& rhs) {
return ( get<2>(lhs) < get<2>(rhs) ) ||
((get<2>(lhs) == get<2>(rhs)) && (( get<0>(lhs) < get<0>(rhs) ))) ||
((get<2>(lhs) == get<2>(rhs)) && (( get<0>(lhs) == get<0>(rhs) )) && (( get<1>(lhs) < get<1>(rhs) ))) ;
}
struct Instance_data{
map<tup3Int,double, bool(*)(const tup3Int&,const tup3Int&)> pro_r;
};
int main ()
{
Instance_data instance;
bool(*tup_comp_ptr)(const tup3Int&,const tup3Int&) = tup_comp;
instance.pro_r = map<tup3Int,double,bool(*)(const tup3Int&,const tup3Int&)>(tup_comp_ptr);
map<tup3Int,int,bool(*)(const tup3Int&,const tup3Int&)>::const_iterator iter3 = instance.pro_r.begin();
map<tup3Int,int,bool(*)(const tup3Int&,const tup3Int&)> hello;
map<tup3Int,int,bool(*)(const tup3Int&,const tup3Int&)>::const_iterator iter2 = hello.begin();
return 0;
}
error: conversion from ‘std::map, double, bool (*)(const std::tuple&, const std::tuple&)>::iterator {aka std::_Rb_tree_iterator, double> >}’ to non-scalar type ‘std::map, int, bool (*)(const std::tuple&, const std::tuple&)>::const_iterator {aka std::_Rb_tree_const_iterator, int> >}’ requested map::const_iterator iter3 = pro_r.begin();
Aucun commentaire:
Enregistrer un commentaire