hash_map with string keys :"instantiated from here" error & STL questions
Konstantinos Pachopoulos
kostaspaxos@yahoo.gr
Tue Aug 28 20:53:00 GMT 2007
Hi,
Greetings; that my first gcc post. Here's the code, that causes the error.
FinancialProductsMatrix.h:
class FinancialProductsMatrix
{
private:
...
//maps currency names(ISO namings) to a specific row and column
//of the matrix (row_num==col_num)
hash_map<string,int> fProductToId_;
...
double getEquivalance4MatrixId(int row, int column); //private method
...
public:
//get the (fromProduct->toProduct) equivalance value
double getEquivalance4ISONames(string fromProduct,string toProduct);
}
FinancialProductsMatrix.cc
double FinancialProductsMatrix::getEquivalance4MatrixId(int row, int column)
{
if (row < column)
{
return (double)equivMatrix_[2*row+column-1];
}
else
{
return (double)(1/equivMatrix_[2*column+row-1]);
}
}//getEquivalance4MatrixId
double FinancialProductsMatrix::getEquivalance4ISONames(string fromProduct,string toProduct)
{
//THIS IS WHERE I GET THE ERROR!
return (double)getEquivalance4MatrixId( (int)(fProductToId_[fromProduct]), (int)(fProductToId_[toProduct]) );
}//getEquivalance4ISONames
Compiling it, i get:
...
Running "make -f nbproject/Makefile-Debug.mk build/Debug/GNU-Generic/FinancialProductsMatrix.o" in /shared/kostas/programming/c++/arbigames
mkdir -p build/Debug/GNU-Generic
g++ -c -g -o build/Debug/GNU-Generic/FinancialProductsMatrix.o FinancialProductsMatrix.cc
In file included from /usr/include/c++/4.1.3/backward/hash_map.h:59,
from FinancialProductsMatrix.h:4,
from FinancialProductsMatrix.cc:1:
/usr/include/c++/4.1.3/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
/usr/include/c++/4.1.3/ext/hashtable.h: In member function ‘size_t __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::_M_bkt_num_key(const _Key&, size_t) const [with _Val = std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _HashFcn = __gnu_cxx::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _ExtractKey = std::_Select1st<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >, _EqualKey = std::equal_to<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<int>]’:
/usr/include/c++/4.1.3/ext/hashtable.h:600: instantiated from ‘size_t __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::_M_bkt_num(const _Val&, size_t) const [with _Val = std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _HashFcn = __gnu_cxx::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _ExtractKey = std::_Select1st<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >, _EqualKey = std::equal_to<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<int>]’
/usr/include/c++/4.1.3/ext/hashtable.h:1007: instantiated from ‘void __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::resize(size_t) [with _Val = std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _HashFcn = __gnu_cxx::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _ExtractKey = std::_Select1st<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >, _EqualKey = std::equal_to<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<int>]’
/usr/include/c++/4.1.3/ext/hashtable.h:795: instantiated from ‘typename __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::reference __gnu_cxx::hashtable<_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc>::find_or_insert(const _Val&) [with _Val = std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _HashFcn = __gnu_cxx::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _ExtractKey = std::_Select1st<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >, _EqualKey = std::equal_to<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<int>]’
/usr/include/c++/4.1.3/ext/hash_map:233: instantiated from ‘_Tp& __gnu_cxx::hash_map<_Key, _Tp, _HashFcn, _EqualKey, _Alloc>::operator[](const typename __gnu_cxx::hashtable<std::pair<const _Key, _Tp>, _Key, _HashFcn, std::_Select1st<std::pair<const _Key, _Tp> >, _EqualKey, _Alloc>::key_type&) [with _Key = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Tp = int, _HashFcn = __gnu_cxx::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _EqualKey = std::equal_to<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Alloc = std::allocator<int>]’
FinancialProductsMatrix.cc:125: instantiated from here
/usr/include/c++/4.1.3/ext/hashtable.h:596: error: no match for call to ‘(const __gnu_cxx::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >) (const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)’
make: *** [build/Debug/GNU-Generic/FinancialProductsMatrix.o] Error 1
Build failed. Exit value 2.
1/I got an answer, that the error has to do with hash_map not being able
to handle string objects. First, can somebody confirm that?
2/I read somewhere, that hash_map is not "standard". What does this
mean? Doesn't libstdc++ implement the sgi STL "standard"?
Is this the answer? :)
5.3 What about the STL from SGI?
The STL from SGI <http://www.sgi.com/tech/stl/>, version 3.3, was the
final merge of the STL codebase. The code in libstdc++ contains many
fixes and changes, and the SGI code is no longer under active
development. We expect that no future merges will take place.
In particular, |string| is not from SGI and makes no use of their "rope"
class (which is included as an optional extension), nor is |valarray|
and some others. Classes like |vector<>| are, however we have made
significant changes to them since then.
The FAQ for SGI's STL (one jump off of their main page) is recommended
reading.
3/ If this is the answer, where can i find an libstdc++ API, that
contains the libstdc++ STL API as well? Maybe something the SUN JDK API -yes
i am a Java coder wanting to learn C++...
4/Then i followed this sgi STL example:
http://www.sgi.com/tech/stl/hash_map.html, which didn't work.
Since i am now learning C++, can somebody tell me what i must and
explain a little? or point me to a link about this issue?
Thanks a lot everybody
More information about the Libstdc++
mailing list