error: ISO C++ forbids declaration of 'hash_map' with no type
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
error: ISO C++ forbids declaration of 'hash_map' with no type
Hi,
here's the following header file, which produces the errors seen after it. I am using the "newer" hash_map (ext/hash_map), not backward compatibility one (backward/hash_map.h) and g++ 4.1:
Code:
#ifndef _FinancialProductsMatrix_H
#define _FinancialProductsMatrix_H
#include <ext/hash_map>
#include <string>
#include <iostream>
#include <boost/lexical_cast.hpp>
typedef std::string string;
/*****************************************
* FinancialProductsMatrix.h
* =======================================
*
* the form of the matrix & compression issues:
* (1) equivalanceFromTo(currency1,currency2)==
* 1 / equivalanceFromTo(currency2,currency1)
* (2) equivalanceFromTo(currency1,currency1)==1
*
* Given 1 and 2 and for a number N of currencies, we do not need a full real
* matrix of size (N*N), but storage of size (N*N)-(#diagonial cells)-(#cells of the
* lower left part of matrix seperated by the main diagonal). That is N*(N-1)/2
* double memory cells in total.
*
* Naming conventions:
* We will refer to the number of double cells as "the matrix" - although not a
* real full matrix.
* We will refer to the lower left part of matrix seperated by the main diagonal
* as the "lower half" and to the upper right part as the "upper half"
*
*****************************************/
//Explicit template specialization of hash of a string class,
//which just uses the internal char* representation as a wrapper.
//hash<const char*> has already been defined
struct hash
{
size_t operator() (const string& x) const
{
return hash()(x.c_str());
}
};
struct eqstr
{
bool operator()(string s1, string s2) const
{
return strcmp(s1.c_str(), s2.c_str()) == 0;
}
};
class FinancialProductsMatrix
{
private:
//CLASS MEMBER FIELDS
//
//number of financial products (either currency, or bonds, etc)
int numOfFProducts_;
//the matrix, that stores the currency equivalance
double *equivMatrix_;
//maps currency names(ISO namings) to a specific row and column
//of the matrix (row_num==col_num)
////////////////////////////
//PROBLEMATIC LINE BELOW!!!!!!!!//
////////////////////////////
hash_map<string,int,hash,eqstr> fProductToId_;
//maps a specific row and column of the matrix (row_num==col_num) to
//currency names(ISO namings)
////////////////////////////
//PROBLEMATIC LINE BELOW!!!!!!!!//
////////////////////////////
hash_map<int,string> idToFProduct_;
//the next "product id", that will be used for the new financial product,
//that will be enlisted. Essentially the row and column (column==row),
//that this product will take over in the matrix.
int nextFProductId_;
////////////////////////////////////////////////////////////////////////
//CLASS MEMBER METHODS
//
//directly access the matrix and change the equivalance value kept
//in the cell specified by row and column
void updateEquivalance4MatrixId(int row, int column,double value);
//directly access the matrix and get the equivalance value kept
//in the cell specified by row and column
double getEquivalance4MatrixId(int row, int column);
//sets all doubles values of the matrix to 0.0
void initMatrix();
////////////////////////////////////////////////////////////////////////
public:
//constructor
FinancialProductsMatrix(int numOfFProducts);
//destructor
~FinancialProductsMatrix();
//update the (fromProduct->toProduct) equivalance value
void updateEquivalance4ISONames(string fromProduct, string toProduct,double value);
//get the (fromProduct->toProduct) equivalance value
double getEquivalance4ISONames(string fromProduct,string toProduct);
//creates the entries to the suitable tables, needed for enlisting a
//new financial product
bool enlistNewFProduct(string name);
//returns the number of financial products
int getFProductsNumber();
//print the equivalance values
string printMatrix();
};
#endif
I get the following compiler errors- the problematic sources lines have been marked with comments in the source code:
Code:
Running "rm -rf build/Debug/GNU-Generic/FinancialProductsMatrix.o" in /shared/kostas/programming/c++/arbigames
Clean successful. Exit value 0.
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
FinancialProductsMatrix.h:67: error: ISO C++ forbids declaration of ‘hash_map’ with no type
FinancialProductsMatrix.h:67: error: expected ‘;’ before ‘<’ token
FinancialProductsMatrix.h:72: error: ISO C++ forbids declaration of ‘hash_map’ with no type
FinancialProductsMatrix.h:72: error: expected ‘;’ before ‘<’ token
FinancialProductsMatrix.cc: In member function ‘double FinancialProductsMatrix::getEquivalance4ISONames(string, string)’:
FinancialProductsMatrix.cc:126: error: ‘fProductToId_’ was not declared in this scope
FinancialProductsMatrix.cc: In member function ‘void FinancialProductsMatrix::updateEquivalance4ISONames(string, string, double)’:
FinancialProductsMatrix.cc:137: error: ‘fProductToId_’ was not declared in this scope
FinancialProductsMatrix.cc: In member function ‘bool FinancialProductsMatrix::enlistNewFProduct(string)’:
FinancialProductsMatrix.cc:156: error: ‘idToFProduct_’ was not declared in this scope
FinancialProductsMatrix.cc:157: error: ‘fProductToId_’ was not declared in this scope
FinancialProductsMatrix.cc: In member function ‘string FinancialProductsMatrix::printMatrix()’:
FinancialProductsMatrix.cc:188: error: ‘idToFProduct_’ was not declared in this scope
make: *** [build/Debug/GNU-Generic/FinancialProductsMatrix.o] Error 1
Build failed. Exit value 2.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.