Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: question on...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 10 Topic 45739 of 47034
Post > Topic >>

Re: question on map< list<T>::iterator, int>

by =?utf-8?Q?David_C=C3=B4me?= <davidcome@[EMAIL PROTECTED] > May 3, 2008 at 03:06 PM

On Sat, 03 May 2008 14:48:01 +0200, subramanian100in@[EMAIL PROTECTED]
 India  =

<subramanian100in@[EMAIL PROTECTED]
> wrote:

> Consider the program x.cpp :
>
> #include <cstdlib>
> #include <iostream>
> #include <list>
> #include <map>
>
> using namespace std;
>
> int main()
> {
>         map<list<int>::iterator, int> m;
>
>         list<int> c;
>         c.push_back(100);
>
>         // m[c.begin()] =3D 10;
>
>         return EXIT_SUCCESS;
> }
>
> This program compiles fine with the command
> g++ -std=3Dc++98 -pedantic -Wall -Wextra  x.cpp
>
> However if I remove the comment, I get compilation error because
> operator '<' is not defined for list<T>::iterator. Why doesn't the
> compiler give this error for
> 'map<list<int>::iterator, int> m;' itself. That is, in this first
> statement inside main() itself, the compiler can know that the less-
> than operator cannot be defined for the key type. So, why does the
> compiler wait for an element to be pushed on to the map to flag the
> error ?
>
> Kindly clarify
>
> Thanks
> V.Subramanian

A map is alway sorted by <.
To use an objet like a key for a std::map, these objet must have defined=
  =

operator<.
 




 10 Posts in Topic:
question on map< list::iterator, int>
"subramanian100in@[E  2008-05-03 05:48:01 
Re: question on map< list::iterator, int>
=?utf-8?Q?David_C=C3=B4me  2008-05-03 15:06:58 
Re: question on map< list::iterator, int>
Paul Brettschneider <p  2008-05-03 15:21:01 
Re: question on map< list::iterator, int>
Pete Becker <pete@[EMA  2008-05-03 10:08:27 
Re: question on map< list::iterator, int>
andrew.smith.cpp@[EMAIL P  2008-05-03 22:43:55 
Re: question on map< list::iterator, int>
Ian Collins <ian-news@  2008-05-04 17:57:05 
Re: question on map< list::iterator, int>
=?UTF-8?B?RXJpayBXaWtzdHL  2008-05-04 09:07:24 
Re: question on map< list::iterator, int>
andrew.smith.cpp@[EMAIL P  2008-05-04 21:42:27 
Re: question on map< list::iterator, int>
James Kanze <james.kan  2008-05-05 06:03:42 
Re: question on map< list::iterator, int>
James Kanze <james.kan  2008-05-05 06:12:48 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 2:55:15 CDT 2008.