LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 03-28-2005, 12:48 PM   #1
parms
LQ Newbie
 
Registered: Mar 2005
Posts: 2

Rep: Reputation: 0
Question C++ question


I am running gcc version 3.2.2 20030222 (Red Hat Linux
3.2.2-5).

I am a relative newbee to c++ (haven't used it in a
while).

In my .h file:

#include <ext/hash_map>

class HTEntry {
public:
double time;
double ttl;
};


typedef hash_map<int, pair<int,HTEntry>, hash<int>,
equal_to<int> > HMap;


class Hash_Table
{
public:
void increment(int, double, double);
int lookup(int,double,double);
int findsize(double,bool);
int estimate_hit(double);
protected:
HMap flows;
};



In the .cc file:
#include <iostream>
#include <sstream>
#include <cmath>
#include <valarray>
#include <string>
#include <sys/types.h>
#include "config.h"
#include "template.h"
#include "flags.h"
#include "delay.h"
#include "rd.h"

using namespace std;

void Hash_Table::increment(int id, double t_now,
double ttl)
{
HMap::iterator iter;
iter=flows.find(id);
double timelived, thresh;
int hits;
// bunch of stuff
}

//other functions that I leave out.

Errors:
In file included from qd.cc:78:
qd.h:154: `hash' was not declared in this scope
qd.h:154: parse error before `>' token
qd.h:173: 'HMap' is used as a type, but is not defined
as a type.
qd.cc: In member function `void
Hash_Table::increment(int, double, double)':
qd.cc:1232: `HMap' undeclared (first use this
function)
qd.cc:1232: (Each undeclared identifier is reported
only once for each
function it appears in.)
qd.cc:1232: parse error before `::' token
qd.cc:1233: `iter' undeclared (first use this
function)
qd.cc:1233: `flows' undeclared (first use this
function)
qd.cc: In member function `int
Hash_Table::findsize(double, bool)':
qd.cc:1274: parse error before `::' token
qd.cc: In member function `int Hash_Table::lookup(int,
double, double)':
qd.cc:1360: parse error before `::' token
make: *** [qd.o] Error 1

Similar errors for other functions removed for
simplicity.

Any help is appreciated.
 
Old 03-28-2005, 08:13 PM   #2
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
what are you trying to accomplish?
 
Old 03-29-2005, 01:47 AM   #3
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
hash_map is an extension to the c++ standard library that ships with gcc (as you can see by how it's included), and extensions to libstdc++ live in the __gnu_cxx namespace.

So your typedef in the header should be:
Code:
typedef __gnu_cxx::hash_map<int, std::pair<int,HTEntry>, __gnu_cxx::hash<int>, __gnu_cxx::equal_to<int> > HMap;
Also, for std::pair you need to include <utility> either directly or indirectly.
 
Old 03-29-2005, 11:15 AM   #4
parms
LQ Newbie
 
Registered: Mar 2005
Posts: 2

Original Poster
Rep: Reputation: 0
Hivemind,

Thanks for the useful info. I could get it to compile now.

The code is part of a large system. So, just getting started..

thanks.
 
  


Reply



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
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 04:23 AM
Not your regular GRUB question - just a short question for a fried MBR!! ziphem Linux - General 3 01-31-2005 01:51 PM
2 part question: Speeding up MDK9.1/GNOME question wardialer Linux - Newbie 6 10-14-2004 03:16 PM
login prompt question & kde scheme question JustinCoyan Slackware 2 06-09-2004 02:02 PM
RE: Suse 8.0 hardware question {newbie question, pls help} Radiouk Linux - Distributions 2 06-04-2002 12:53 PM

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

All times are GMT -5. The time now is 11:36 PM.

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