Variables inexlicably flagged as undeclared

ever_thus's Avatar, Join Date: Jan 2007
Contributor
I have several classes all of which show the same problem when they compile - "undeclared variable". Needless to say all the variables are, as far as I can tell, declared. The one pattern I seem to be able to find is that the compiler only complains when they are used as parameters. Otherwise the compiler recognizes them.

I won't bore you with the entire code, here's a sample.

Code:
#pragma once
#include <map>
using std::map;
#include <string>
using std::string;
#include <vector>
using std::vector;
#include <algorithm>


class Dictionary
	{
	private:
		vector <TCHAR*> words;
		LONG ref_cnt;
		string module;
		USHORT rsc_id;
		Dictionary (string module, USHORT rsc_id);
		Dictionary (HMODULE module, USHORT rsc_id, LONG key);
		bool FindWord (string searched) 
			{return binary_search (words.begin (), words.end (), searched);}
		static void init_Mutex (void);
	public:
		virtual ~Dictionary (void);
		static LONG LoadDictionary (string module, USHORT rsrc);
		static void UnloadDictionary (LONG key);
		static void UnloadDictionaries (INT size, LONG keys []);
		static bool FindInDictionary (string searched, LONG key);
		static bool FindInDictionaries (string searched, INT size, LONG keys []);
	};
in FindWord words is flagged as undeclared.

Here's one more
Code:
Dictionary::Dictionary(string module, USHORT rsc_id){
	HMODULE hmodule = LoadLibrary (module.c_str ());
	HRSRC rsc = FindResource (hmodule, MAKEINTRESOURCE (rsc_id), RT_RCDATA);
	TCHAR* chWords = (TCHAR*) LoadResource (hmodule, rsc_id);
	
	TCHAR* token = strtok (chWords, "\0");
	TCHAR* new_string = new char [strlen (token)];
	strcpy (new_string, token);
	words.push_back (token);

	while (token = strtok (NULL, "\0")){
		TCHAR* new_string = new char [strlen (token)];
		strcpy (new_string, token);
		words.push_back (new_string);
	}

	FreeLibrary (hmodule);
	this->module = module;
	this->rsc_id = rsc_id;
	InterlockedIncrement (&ref_cnt);
}
Here token is flagged when passed to strcpy (but not strlen or push_back) as is rsc_id when passed to MAEINTRESOURCE and LoadResource.

What's the cause of these errors. They're driving me nuts.
0
DaWei's Avatar, Join Date: Dec 2006
Team Leader
I see about ten posts a day, by the uninitiated, claiming that they have found bugs in the language. Most of them, like you, can't even explain why the unexpected behavior even seems like a bug.

You haven't explained diddly-squat, other than the fact that your use of the language has failed to provide you with a sugar-tit at the time of the day that you are most accomsted to receive one.

Would you care to expand upon that, in some sort of meaningful detail, or would you just like us to pat you on the butt and have us tell you what a good big boy you are. We are quite likely to assign the latter chore to your mama.

Most error messages telling you that you have failed to declare a variable mean exactly that. They are not being abstruse just to eff you up. Did you think of that? Inquiring minds want to know. I won't bore you with details, they can't possibly be important.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by ever_thus
The one pattern I seem to be able to find is that the compiler only complains when they are used as parameters. Otherwise the compiler recognizes them.
Do you mean to say your compiler does not support the parameterized functions? You probably need to be either switch to some good compiler then.
0
ever_thus's Avatar, Join Date: Jan 2007
Contributor
My compiler is perfect. It recognizesd all the functions and does not say I''m passing the wrong parameters. All it says is that the identifier I'm passing is undeclared. As you can see in the posted code, I do seem to have declared them.

DaWei, I haven't the faintest idea what you're talking about. Who mentioned bugs?
0
ever_thus's Avatar, Join Date: Jan 2007
Contributor
I found the problem. A variable in the first file to be preprocessed was declared as a nonexistent type, messing up all the variables after it.