Witam,
próbuję użyć szablonu std::map. Próbuję skompilować następujący przykład:
int _tmain(int argc, _TCHAR* argv[])
{
typedef std::map <std::string, int> MapType;
MapType data;
// let's declare some initial values to this map
data["Bobs score"] = 10;
data["Martys score"] = 15;
data["Mehmets score"] = 34;
data["Rockys score"] = 22;
data["Rockys score"] = 23; /*overwrites the 22 as keys are unique */
return 0;
}
Niestety kompilator (używam visual C++ 2003) zwraca następujące błędy:
dequetest error C2784: 'bool std::operator <(const std::deque<_Ty,_Alloc> &,const std::deque<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::deque<_Ty,_Ax> &' from 'const std::string'
dequetest error C2676: binary '<' : 'const std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
dequetest error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
dequetest error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
c:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(1170) : see declaration of 'std::operator<'' dequetest error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string' c:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(1170) : see declaration of 'std::operator
<''
dequetest error C2784: 'bool std::operator <(const std::deque<_Ty,_Alloc> &,const std::deque<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::deque<_Ty,_Ax> &' from 'const std::string'
c:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include\deque(999) : see declaration of 'std::operator<'' dequetest error C2784: 'bool std::operator <(const std::deque<_Ty,_Alloc> &,const std::deque<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::deque<_Ty,_Ax> &' from 'const std::string' c:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include\deque(999) : see declaration of 'std::operator
<''
dequetest error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
c:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include\utility(73) : see declaration of 'std::operator<'' dequetest error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string' c:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include\utility(73) : see declaration of 'std::operator
<''
dequetest error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
c:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include\utility(73) : see declaration of 'std::operator<'' dequetest error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string' c:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(655) : see declaration of 'std::operator
<''
dequetest error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
c:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(655) : see declaration of 'std::operator<'' dequetest error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string' c:\Program Files (x86)\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(655) : see declaration of 'std::operator
<''
Czy użycie std:string jako klucza nie jest możliwe? To wtedy jak możnaby mapować wartości względem łańcuchów znaków?
pozdrawiam
Rafał Ziółkowski