LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   error: ISO C++ forbids declaration of 'hash_map' with no type (https://www.linuxquestions.org/questions/programming-9/error-iso-c-forbids-declaration-of-hash_map-with-no-type-581072/)

kpachopoulos 08-30-2007 04:34 PM

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.


95se 08-30-2007 06:30 PM

Holy slashes Batman! Sorry ;) ext/hash_map is in the __gnu_cxx namespace (http://gcc.gnu.org/onlinedocs/libstd...hash__map.html)
Code:

__gnu_cxx::hash_map<int,string> idToFProduct_;
For some reason, g++ gives that error. But only if you declare an unknown generic in the class definition. Like, try this.

Code:

class A
{
        asdf<int> asdf;
}

It'll come up w/ the same error, but for asdf.


All times are GMT -5. The time now is 01:14 AM.