[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
cannot compile hash_map from stlport
From: |
Jim Anderson |
Subject: |
cannot compile hash_map from stlport |
Date: |
Wed, 07 Nov 2007 03:40:26 GMT |
User-agent: |
Thunderbird 1.5.0.13 (X11/20070824) |
I'd like to use the hash_map template from the stlport which I
picked up at sourceforge.net (version 5.1.4). I installed the
library and then create the example given at
http://www.sgi.com/tech/stl/hash_map.html. I've attached
this example (sample.cc) and a simple makefile. The only change I've
made to the example is to add the #include statements
for iostream and hash_map.
---------------
When I compile, I get the following output:
g++ -I/home/jja/work/prog/dev/ind/include/stlport -o sample sample.cc
sample.cc: In function ‘int main()’:
sample.cc:15: error: ‘hash_map’ was not declared in this scope
sample.cc:15: error: expected primary-expression before ‘const’
sample.cc:15: error: expected `;' before ‘const’
sample.cc:17: error: ‘months’ was not declared in this scope
sample.cc:30: error: ‘cout’ was not declared in this scope
sample.cc:30: error: ‘endl’ was not declared in this scope
make: *** [sample] Error 1
----------------
I ran the sample program through cpp to verify that hash_map
is being read in. It appears to be read in, yet I'm getting
the error that 'hash_map' was not declared. I'm guessing
the error message is telling me that the template is not
instansiating the hash_map class that is needed, but I'm
not sure. Can anyone explain the error message and why
the SGI example will not compile?
Jim Anderson
#include <iostream>
#include "hash_map.h"
struct eqstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) == 0;
}
};
int main()
{
hash_map<const char*, int, hash<const char*>, eqstr> months;
months["january"] = 31;
months["february"] = 28;
months["march"] = 31;
months["april"] = 30;
months["may"] = 31;
months["june"] = 30;
months["july"] = 31;
months["august"] = 31;
months["september"] = 30;
months["october"] = 31;
months["november"] = 30;
months["december"] = 31;
cout << "september -> " << months["september"] << endl;
cout << "april -> " << months["april"] << endl;
cout << "june -> " << months["june"] << endl;
cout << "november -> " << months["november"] << endl;
}
sample: sample.cc
g++ -I/home/jja/work/prog/dev/ind/include/stlport -o sample sample.cc
# cpp -I/home/jja/work/prog/dev/ind/include/stlport -o sample sample.cc
- cannot compile hash_map from stlport,
Jim Anderson <=