LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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-22-2005, 07:06 PM   #1
wangjinyi
Member
 
Registered: Sep 2004
Posts: 60

Rep: Reputation: 15
about STL programming


that is the cpp and h file below:
<code>
struct person {
int age;
char name[10];
};

struct GetName {
char* operator()(person one) const { return one.name; }
};

struct EqualKey {
bool operator()(char* c1, char* c2) const { return strcmp(c1, c2) == 0; }
};

int main(void)
{
hashtable<person, char*, hash<char*>, GetName, EqualKey> stuff;
}

#ifndef __HASHTEST_H__
#define __HASHTEST_H__

#include </usr/include/c++/3.2.2/ext/stl_hashtable.h>

#endif
</code>
and, when compile it, output is below:

g++ -g -I. -I/usr/include/c++/3.2.2/ext hashtest.cpp -o mytest -L.
hashtest.cpp: In function `int main()':
hashtest.cpp:19: `hashtable' undeclared (first use this function)
hashtest.cpp:19: (Each undeclared identifier is reported only once for each
function it appears in.)
hashtest.cpp:19: parse error before `,' token
make: *** [all] Error 1


I am sure the exactly h file stl_hashtable.h be in there.
and when i put a key work class before the word hashtable in
function main, the output change to below:

g++ -g -I. -I/usr/include/c++/3.2.2/ext hashtest.cpp -o mytest -L.
hashtest.cpp: In function `int main()':
hashtest.cpp:19: `hash' undeclared (first use this function)
hashtest.cpp:19: (Each undeclared identifier is reported only once for each
function it appears in.)
hashtest.cpp:19: parse error before `*' token
make: *** [all] Error 1

I need your help. anything is helpful.
 
Old 03-24-2005, 08:34 AM   #2
YetAnotherDave
Member
 
Registered: Feb 2005
Posts: 95

Rep: Reputation: 17
"hashtable" is in the __gnu_cxx namespace. You can use "using namespace __gnu_cxx;" to let the compiler know to look there for "hashtable". Also, there is no default constructor for hashtable<...> so you need to specifiy some arguments to "stuff()" as shown below.

The modified version of your program shown below compiles and links ( at least it did for me but I'm using (gcc 3.3) which is different from the version you are using ( gcc 3.2.2 ).


- Dave

Code:
using namespace __gnu_cxx;

struct person {
    int age;
    char name[10];
};

struct GetName {
    char* operator()(person one) const { return one.name; }
};

struct EqualKey {
    bool operator()(char* c1, char* c2) const { return strcmp(c1, c2) == 0; }
};

int main(void)
{
    hash<char*> fcn;
    EqualKey key;
    hashtable<person, char*, hash<char*>, GetName, EqualKey> stuff(0, fcn, key);
}
 
Old 03-24-2005, 05:45 PM   #3
wangjinyi
Member
 
Registered: Sep 2004
Posts: 60

Original Poster
Rep: Reputation: 15
That's the point.
Thanks a lot.
 
  


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
Are the QT suuport STL? Barq Linux - General 1 11-18-2004 10:20 AM
STL errors in Linux sheenak Programming 2 06-22-2004 04:54 AM
c++ and stl G67 Programming 4 12-17-2003 02:36 AM
stl containers champ Programming 2 04-09-2003 05:27 AM
C++ STL problem jaycee999 Programming 5 05-31-2002 03:01 AM

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

All times are GMT -5. The time now is 05:42 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