operator over loading problem?
-
lately when I use STL map as a parameter in a function I have a problem? such as:
void func(const map<struct>& mapUsed)
{
map<struct>::iterator iterMap = mapUsed.begin()
while(iterMap != mapUsed.end())
{
//do something
}
}The vs2008 report an error and when I use const_iterator to instead random iterator It's ok And I wanna know If STL use "const" overloading such as operator == ... If not ? How dose STL do? Thanks a lot! :doh:
-
lately when I use STL map as a parameter in a function I have a problem? such as:
void func(const map<struct>& mapUsed)
{
map<struct>::iterator iterMap = mapUsed.begin()
while(iterMap != mapUsed.end())
{
//do something
}
}The vs2008 report an error and when I use const_iterator to instead random iterator It's ok And I wanna know If STL use "const" overloading such as operator == ... If not ? How dose STL do? Thanks a lot! :doh:
map<struct>
should be more likemap<int, int>
or something. you're indexing one type of thing to another type of thing. you're not just making a vector of structs. even then, if you are making a map of int->structs, then the data type has to be used. the map must know how large of an allotment of memory it has to block off for each part of the map. hope that made sense... -
map<struct>
should be more likemap<int, int>
or something. you're indexing one type of thing to another type of thing. you're not just making a vector of structs. even then, if you are making a map of int->structs, then the data type has to be used. the map must know how large of an allotment of memory it has to block off for each part of the map. hope that made sense...Hi, I'm sorry that I made a mistake! what I mean is when I use STL::map or else Using iterator as a left value and a map<X,Y> as a parameter of a function as bellow
void func(const map<X,Y> mapUsed)
{
map<X,Y>::iterator iterMap = mapUsed.begin(); //IDE report wrong here
while(iterMap != mapUsed.end())
{
//do something
}
}mapUsed.begin() returned a const_iterator it dosen't match with iterator I was confusing that how dose mapUsed know itself is a const one and return const_iterator Did the IDE do it for us or STL used some other way? Thanks a lot!
-
Hi, I'm sorry that I made a mistake! what I mean is when I use STL::map or else Using iterator as a left value and a map<X,Y> as a parameter of a function as bellow
void func(const map<X,Y> mapUsed)
{
map<X,Y>::iterator iterMap = mapUsed.begin(); //IDE report wrong here
while(iterMap != mapUsed.end())
{
//do something
}
}mapUsed.begin() returned a const_iterator it dosen't match with iterator I was confusing that how dose mapUsed know itself is a const one and return const_iterator Did the IDE do it for us or STL used some other way? Thanks a lot!
>> I was confusing that how dose mapUsed know itself is a const one and return const_iterator... It depends on how "mapUsed" is declared for the function func : void func(const map<X,Y> mapUsed) since "mapUsed" is declared as a const, the compiler naturally uses the const_iterator. - Bio.
-
>> I was confusing that how dose mapUsed know itself is a const one and return const_iterator... It depends on how "mapUsed" is declared for the function func : void func(const map<X,Y> mapUsed) since "mapUsed" is declared as a const, the compiler naturally uses the const_iterator. - Bio.
-
Most welcome york528 :)