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 08:03 AM
Doubt??? [scope of variables] qzv2jm Shell Programming and Scripting 1 03-04-2008 09:19 AM
Access Awk Variables Outside Scope Amruta Pitkar Shell Programming and Scripting 7 01-15-2008 09:17 AM
pthread_create and scope usage jenmead High Level Programming 3 09-20-2006 05:16 PM
scope sundaresh High Level Programming 7 06-28-2006 12:19 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
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

Last edited by J.P; 04-24-2002 at 04:45 PM..
  #2 (permalink)  
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0