LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-30-2007, 04:34 PM   #1
kpachopoulos
Member
 
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 705

Rep: Reputation: 30
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.
 
Old 08-30-2007, 06:30 PM   #2
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
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.

Last edited by 95se; 08-30-2007 at 06:34 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ISO C++ forbids comparison between pointer and integer BarryKamp Programming 5 04-25-2007 09:06 PM
error: ISO C++ forbids comparison ... NEED HELP URGENT !!! lx3000 Programming 5 10-02-2006 02:48 PM
ISO C++ forbids declaration of... lucky6969b Programming 3 03-23-2006 07:54 AM
printk --- ISO C90 forbids mixed declaration and code Igor007 Programming 3 09-08-2005 04:05 AM
ISO C++ forbids comparison between pointer and integer? pimaster Programming 1 11-06-2003 01:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration