T
Tim Partridge
I want to use a map as a container storing foos and ints. I want to be
able to create pointers to the foos after they're in the container. How
can I do this? My following attempt fails:
#include <map>
class foo {
public:
bool operator<( const foo &f ) const { return true; }
};
int main() {
map< foo, int > m;
foo f;
m.insert( pair< foo, int >( f, 1 ) );
foo *fp = &(m.begin()->first); // this line gives an error
return 0;
}
In g++ 2.95.2, the following error is given:
main.cc:13: initialization to `foo *' from `const foo *' discards
qualifiers
So why is m.begin() returning a const_iterator instead of just a regular
iterator?
Thanks,
Tim Partridge
able to create pointers to the foos after they're in the container. How
can I do this? My following attempt fails:
#include <map>
class foo {
public:
bool operator<( const foo &f ) const { return true; }
};
int main() {
map< foo, int > m;
foo f;
m.insert( pair< foo, int >( f, 1 ) );
foo *fp = &(m.begin()->first); // this line gives an error
return 0;
}
In g++ 2.95.2, the following error is given:
main.cc:13: initialization to `foo *' from `const foo *' discards
qualifiers
So why is m.begin() returning a const_iterator instead of just a regular
iterator?
Thanks,
Tim Partridge