Function scoping

I'm having problems with the scope of some functions. I'm creating a dictionary class that uses an enty class to store the entries. Now I have this function that generates a and index containing a keyword and all the pages that contain the keyword.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
void generateDictionnary(char L[MAX_NB_LINK][MAX_SIZE_URL], char *words, char *urls){
	char URL[MAX_SIZE_URL];
	//1)Rempli Index[] avec les mots
	ifstream file;
	file.open(words);
	while(!file.eof()){
		file.getline(URL, MAX_SIZE_URL);
		if(!estPresent(URL))
			inserer(URL);
	}
	//Cherche Pour le mots dans Index[i] tout les pages webs qui contient ce MC
	for(int mot = 0; mot < indiceCourant; mot++){
		//Ouvre le fichier qui se situe a la Ieme ligne de L pour le mot X
		for(int ligne = 0; ligne < nmbr_liens; ligne++){
			ifstream file2;
			file2.open(L[ligne]);
			bool contient = false;
			//Ouvjre la Jeme ligne de la page I
			for(int line_file = 0; !file.eof() and !contient; line_file++){
				file2.getline(URL, MAX_SIZE_URL);
				if(contienMot(Index[mot]->name, URL)){
					inserer(mot, ligne);
					contient = true;
				}		
			}
		}
	}
}


It calls some other functions (all of them are members of the class Dictionnaire) and mainly messes around with the **Index and indiceCourant (current Index) which are the private members of a Dictionnaire. Here are the errors I'm getting:

ALL.cpp: In function ‘void generateDictionnary(char (*)[300], char*, char*)’:
ALL.cpp:124: error: ‘estPresent’ was not declared in this scope
ALL.cpp:125: error: ‘inserer’ was not declared in this scope
ALL.cpp:128: error: ‘indiceCourant’ was not declared in this scope
ALL.cpp:137: error: ‘Index’ was not declared in this scope
ALL.cpp:137: error: ‘contienMot’ was not declared in this scope
ALL.cpp:138: error: ‘inserer’ was not declared in this scope

All of the mentioned functions are declared and defined above so I don't understand the scoping problem.

I'm also having problems with some global constants. I want to put the Dictionnaire class in a separate .cpp. The problem is that it uses some global constants and arrays which are found in the main. If someone could explain to me how to include them for the Dictionnaire.cpp.
All of the mentioned functions are declared and defined above so I don't understand the scoping problem.

No they are not. They need to be defined within this function, or be passed to the function, for you to use them how you are.
I don't get it :(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Dictionnaire{
	class Entry{
	public:
		string motClef;
		Liste pages;
	};
public:
	Dictionnaire();
	Dictionnaire(const Dictionnaire& orig);
	Dictionnaire& operator=(const Dictionnaire& orig);
	void inserer(char*);
	void inserer(int m, int key);
	int chercher(char*);
	bool estPresent(char*);
	bool contientMot(string str, char ligne[MAX_SIZE_URL]);
	void generateDictionnary(char L[MAX_NB_LINK][MAX_SIZE_URL], char *words, char *urls);
	~Dictionnaire();
	Liste returnPages(char *v);
private:
	int indiceCourant;
	
	Entry **Index;
	
	void effacer();
	void copier(const Dictionnaire& orig);		
};	


As you can see all of the functions that have the scoping problem are a part of the Dictionnaire class aswell as the generateDictionary(). I never had problems calling class specific function within another class specific functions before.


EDIT: Nevermind -_-
Just noticed that it was void generateDictionnary() instead of void Dictionnaire::generateDictionnary() >_< That's it no more coding @ 6 AM
Last edited on
Topic archived. No new replies allowed.