The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-24-2002
J.P's Avatar
J.P J.P is offline
Registered User
 

Join Date: Nov 2001
Location: Sweden
Posts: 67
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.
Reply With Quote
Forum Sponsor
  #2  
Old 04-25-2002
J.P's Avatar
J.P J.P is offline
Registered User
 

Join Date: Nov 2001
Location: Sweden
Posts: 67
Lightbulb solved it!

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 ]
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0