Re: [Boost-users] [multi_index] passing 'cons t TYPE' as 'this' argument discards qualifiers
----- Mensaje original ----- De: damny@web.de Fecha: Martes, Diciembre 25, 2007 5:17 pm Asunto: [Boost-users] [multi_index] passing 'cons t TYPE' as 'this' argument discards qualifiers Para: boost-users@lists.boost.org
merry xmas everyone,
Merry Xmas :) [...]
class cClass { private: int att1; public: std::string nme; // name int idf; // identifier cClass(); cClass(std::string nme, int idf); int get_attribute(); };
[...]
mMapByNme::iterator itrNme = locMsg.get<0>().find("name1"); mMapByIdf::iterator itrIdf = locMsg.get<1>().find(456); printf( "att1 = %d\n", itrNme->get_attribute() ); [...] main.cpp: In function `int main()': main.cpp:33: error: passing 'const cClass' as 'this' argument of 'int cClass::get_attribute()' discards qualifiers Process terminated with status 1 (0 minutes, 20 seconds)
any hints how to solve the problem?
The problem here is that elements of a multi_index_container are immutable, and the iterators ony grant const access to them. In this regard, the behavior is the same as that of a regular std::set. To solve your particular problem you can const-qualify the offending member function: int get_attribute() const;
how to encapsulate this special multi_index into a class, that fits the above description of the needed 'map'.
You should probably consider whether Boost.Bimap could be a better approach, but I see you're already discussing this issue with Matías.
are there possibilities to avoid the 'std::string' for the 'name' key?
I'm not getting this question. Could you please elaborate?
where are the more easier examples for C++-templates/boost newbies like me :o) ?
HTH, Joaquín M López Muñoz Telefónica, Investiación y Desarrollo
participants (1)
-
"JOAQUIN LOPEZ MU?Z"