Hi,
I'm in the process of porting some C++ code written for a linux environment from gcc version 2.96 yo 3.4.3.
Unfortunately, I got stuck when it came to porting some STL map related code. I did some research but I can't seem to find the modification required to overcome the problem.
In the header file I've got the following map defined:
// Map of Port Description -> PortInfo*
typedef map<Description, PortInfo*, less<Description> > PortDescriptionsMap;
typedef PortDescriptionsMap::iterator PortDescriptionsMapIterator;
typedef PortDescriptionsMap::value_type PortDescriptionsMapValue;
typedef pair<PortDescriptionsMapIterator, bool > DescriptionsInsertResult;
PortDescriptionsMap portDescriptionsMap;
where:
'Description' is a class representing an array of characters and
'PortInfo' is another class
When I compile the following code segment I get an error, which is associated to the last line in the code segment:
if (portNumbersMap.size() > 0)
{
PortNumbersMapIterator iterator = portNumbersMap.begin();
==>> if(iterator != portDescriptionsMap.end())
ports.cpp:479: error: no match for 'operator!=' in 'iterator != (((std::map<Description, PortInfo*, std::less<Description>, std::allocator<std::pair<const Description, PortInfo*> > >*)((Ports*)this)) + 84u)->std::map<_Key, _Tp, _Compare, _Alloc>::end [with _Key = Description, _Tp = PortInfo*, _Compare = std::less<Description>, _Alloc = std::allocator<std::pair<const Description, PortInfo*> >]()'
/usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../include/c++/3.4.3/bits/stl_tree.h:213: note: candidates are: bool std::_Rb_tree_iterator<_Tp>::operator!=(const std::_Rb_tree_iterator<_Tp>&) const [with _Tp = std::pair<const PortNumber, Description>]
__________________________________________________
The compile error refers to templates. I expect they are implicitly used in maps. I also realise that 'typename' needs to be used when we've got templates. However, if I add it to the header file as follows
typedef typename PortDescriptionsMap::iterator PortDescriptionsMapIterator;
or in the code itself
typename PortNumbersMapIterator iterator = portNumbersMap.begin();
I get 'typename' used outside template error.
I would greatly appreciate any suggestions from others in the community.
Thanks in advance,
Shiraz
Melbourne, Australia