Variables inexlicably flagged as undeclared

Discussion in 'C' started by ever_thus, Jun 14, 2007.

  1. ever_thus

    ever_thus New Member

    Joined:
    Jan 3, 2007
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    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.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    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.
     
  4. ever_thus

    ever_thus New Member

    Joined:
    Jan 3, 2007
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    0
    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?
     
  5. ever_thus

    ever_thus New Member

    Joined:
    Jan 3, 2007
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    0
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice