![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Variables scope. | dinjo_jo | Shell Programming and Scripting | 13 | 09-10-2008 04:03 AM |
| Doubt??? [scope of variables] | qzv2jm | Shell Programming and Scripting | 1 | 03-04-2008 06:19 AM |
| Access Awk Variables Outside Scope | Amruta Pitkar | Shell Programming and Scripting | 7 | 01-15-2008 06:17 AM |
| pthread_create and scope usage | jenmead | High Level Programming | 3 | 09-20-2006 01:16 PM |
| scope | sundaresh | High Level Programming | 7 | 06-28-2006 08:19 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
C++: scope, different files etc..
I'm having a problem getting this to work..
I got 3 files, start.C - Where i got my main() function Menu.C & Menu.h - Where I'm trying to use hash_map start.C #include <iostream> #include "Menu.h" using namespace std; int main() { /* test code here */ return 0; } Menu.h #ifndef _MENU_H_ #define _MENU_H_ class Menu { public: Menu() {*} ~Menu() {*} private: hash_map< const char*, int, hash<const char*>, eqstr > hashmap; }; #endif Menu.C #include <iostream> #include <string> #include <hash_map> struct eqstr { bool operator()(int s1, int s2) { return s1 == s2; } }; #include "Menu.h" ----------------------------- The code doesn't actually do anything now but I just want to get this working before i continue my little project. I've tried using hash_map in a separate file and it worked. Compiler errors for the code above: [jp@Slacktop:~/devel/cpp/001/] g++ start.C Menu.C In file included from start.C:2: Menu.h:10: `hash' was not declared in this scope Menu.h:10: parse error before `char' Menu.h: In method `Menu::Menu()': Menu.h:6: parse error before character 0240 Menu.h: In method `Menu::~Menu()': Menu.h:7: parse error before character 0240 In file included from Menu.C:11: Menu.h: In method `Menu::Menu()': Menu.h:6: parse error before character 0240 Menu.h: In method `Menu::~Menu()': Menu.h:7: parse error before character 0240 The second line "'hash' was not declared in this scope" is probably the root of this evil error but I'm clueless on how to fix this.. any suggestions? guidelines and recommendations on how to use multiple files are also appreciated. Slackware 8.0, Linux 2.4.5, G++ 2.95.3
__________________
[ Please put signature here ] Last edited by J.P; 04-24-2002 at 12:45 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Menu.C
#include <iostream> #include <string> #include "Menu.h" /* Coooooooooode */ Menu.h #ifndef _MENU_H_ #define _MENU_H_ #include <hash_map> struct eqstr { bool operator()(int s1, int s2) { return s1 == s2; } }; class Menu { public: Menu() { } ~Menu() { } private: hash_map< const char*, int, hash<const char*>, eqstr > hashmap; }; #endif
__________________
[ Please put signature here ] |
||||
| Google The UNIX and Linux Forums |