Topic: const key type in map
Author: anjul.srivastava@sanchez.com
Date: 2000/05/03 Raw View
The following compiler error message is said to happen because the
program violates the standard. According to the compiler team,
using 'const int' as the key type for map<> is invalid because Row 1 of
Table 69 seems to says that the key must be assignable and therefore
non-const.
1. Is this correct? (that you cannot use const type keys)
2. If so, what is the reason? Many compilers (like gcc) are able to
implement all functions of map<> with const key types.
Thanks,
Anjul.
>>#include <map>
>>
>>class DE_SQL
>>{
>>public:
>> DE_SQL(void);
>>protected:
>> std::map<const int, int> mTable;
>>};
>>
>>DE_SQL::DE_SQL(void)
>>{
>>}
>>--------------------------------------------------
>>% CC6 -V -c map.cpp
>>CC6: Sun WorkShop 6 00/03/06 C++ 5.1
>>ccfe: Sun WorkShop 6 00/03/06 C++ 5.1
>>"/workspace/.mnt/buffy3/markw/buildbin-
030600/SC5.1/include/CC/Cstd/map",
>>line 251: Error: Multiple declaration for std::map<const int, int,
>>std::less<const int>, std::allocator<std::pair<const int,
>>int>>>::insert(const std::pair<const int, int>&).
>>"map.cpp", line 9: Where: While specializing "std::map<const int,
int,
>>std::less<const int>, std::allocator<std::pair<const int, int>>>".
>>"map.cpp", line 9: Where: Specialized in non-template code.
>>1 Error(s) detected.
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]