Sponsored Content
Top Forums Programming C++: scope, different files etc.. Post 20330 by J.P on Wednesday 24th of April 2002 03:37:40 PM
Old 04-24-2002
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.

Smilie


Slackware 8.0, Linux 2.4.5, G++ 2.95.3

Last edited by J.P; 04-24-2002 at 04:45 PM..
 

10 More Discussions You Might Find Interesting

1. Programming

C++ variable scope and mutexes

I've been wondering if I can make mutexes much easier to use in C++ with creative use of a locking class and variable scope, but I'm not sure if things happen in the order I want. Here's pseudocode for something that could use the class: int someclass::getvalue() { int retval; ... (0 Replies)
Discussion started by: Corona688
0 Replies

2. Programming

scope

Each thread has a copy of auto variables within a function, but variables declared as static within a function are common to all threads. To circumvent this can static variables be placed outside the function. If so, will the scope of the variable be file only or will it be extern, and will each... (7 Replies)
Discussion started by: sundaresh
7 Replies

3. AIX

Scope of AIX

What is the scope of AIX as I am starting my career as a fresher in AIX administration?? (4 Replies)
Discussion started by: abhishek27
4 Replies

4. Shell Programming and Scripting

Doubt about variables scope

I call my script with two parameters myscript.sh aaa bbb What is the way to access $1 and $2 values inside a function? I call the function like this myfuntion $1 $1 but inside of the function, $1 and $2 are empty. Any suggestions? thank you in advanced. (1 Reply)
Discussion started by: aristegui
1 Replies

5. Shell Programming and Scripting

Variables scope.

Hi , I'm trying to change the variable value in a while loop , however its not working it seems that the problem with subshells while reading the file. #!/bin/sh FLAG=0; cat filename | while read data do FLAG=1; done echo $FLAG Should display 1 instead displays 0 (13 Replies)
Discussion started by: dinjo_jo
13 Replies

6. Shell Programming and Scripting

scope of the variable - Naga

Hi All, I am new to unix shell scripting, in the below script "num" is an input file which contains a series of numbers example : 2 3 5 8 I want to add the above all numbers and want the result finally outside the while loop. it prints the value zero instead of the actual expected... (13 Replies)
Discussion started by: nagnatar
13 Replies

7. Shell Programming and Scripting

variable scope

Hi, I want to know about the variable scope in shell script. How can we use the script argument inside the function? fn () { echo $1 ## I want this argument should be the main script argument and not the funtion argument. } also are there any local,global types in shell script? if... (3 Replies)
Discussion started by: shellwell
3 Replies

8. Shell Programming and Scripting

bc: scope doesn't work for me

I am trying to use bc to calculate the difference between two nano second time stamps. bc does the calculation but seems to ignore the scale option: micro_start=$(date +%s.%N) # .. some stuff happens here micro_stop=$(date +%s.%N) TOT=$(echo "scale=3; $micro_stop - $micro_start" | bc)... (2 Replies)
Discussion started by: LostInTheWoods
2 Replies

9. Shell Programming and Scripting

Help with retaining variable scope

Hi, I use Korn Shell. Searched Forum and modified the way the file is input to the while loop, but still the variable does not seem to be retaining the final count. while read name do Tmp=`echo $name | awk '{print $9 }'` Count=`cat $Tmp | wc -l`... (6 Replies)
Discussion started by: justchill
6 Replies

10. Shell Programming and Scripting

Variable scope in bash

Hello! Before you "bash" me with - Not another post of this kind Please read on and you will understand my problem... I am using the below to extract a sum of the diskIO on a Solaris server. #!/bin/sh PATH=/usr/bin:/usr/sbin:/sbin; export PATH TEMP1="/tmp/raw-sar-output.txt$$"... (3 Replies)
Discussion started by: haaru
3 Replies
Prophet::Web::Menu(3pm) 				User Contributed Perl Documentation				   Prophet::Web::Menu(3pm)

NAME
Prophet:Web::Menu - Handle the API for menu navigation METHODS
new PARAMHASH Creates a new Prophet::Web::Menu object. Possible keys in the PARAMHASH are "label", "parent", "sort_order", "url", and "active". See the subroutines with the respective name below for each option's use. label [STRING] Sets or returns the string that the menu item will be displayed as. parent [MENU] Gets or sets the parent Prophet::Web::Menu of this item; this defaults to null. This ensures that the reference is weakened. sort_order [NUMBER] Gets or sets the sort order of the item, as it will be displayed under the parent. This defaults to adding onto the end. link Gets or set a Jifty::Web::Link object that represents this menu item. If you're looking to do complex ajaxy things with menus, this is likely the option you want. target [STRING] Get or set the frame or pseudo-target for this link. something like _blank class [STRING] Gets or sets the CSS class the link should have in addition to the default classes. This is only used if "link" isn't specified. url Gets or sets the URL that the menu's link goes to. If the link provided is not absolute (does not start with a "/"), then is is treated as relative to it's parent's url, and made absolute. active [BOOLEAN] Gets or sets if the menu item is marked as active. Setting this cascades to all of the parents of the menu item. child KEY [, PARAMHASH] If only a KEY is provided, returns the child with that KEY. Otherwise, creates or overwrites the child with that key, passing the PARAMHASH to "new" in Jifty::Web::Menu. Additionally, the paramhash's "label" defaults to the KEY, and the "sort_order" defaults to the pre-existing child's sort order (if a "KEY" is being over- written) or the end of the list, if it is a new "KEY". active_child Returns the first active child node, or "undef" is there is none. delete KEY Removes the child with the provided KEY. children Returns the children of this menu item in sorted order; as an array in array context, or as an array reference in scalar context. render_as_menubar [PARAMHASH] Render menubar with YUI menu, suitable for an application's menu. It can support arbitary levels of submenu. as_link Return this menu item as a "Jifty::Web::Link", either the one we were initialized with or a new one made from the "/label" and "/url" If there's no "/url" and no "/link", renders just the label. perl v5.10.1 2009-12-22 Prophet::Web::Menu(3pm)
All times are GMT -4. The time now is 04:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy