Archived

This topic is now archived and is closed to further replies.

undeclared identifier

This topic is 5649 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi there, I have a main.cpp and a init.cpp, in de main.cpp I have the winmain function and the window creation and in the init.cpp I have the initialisation of d3d8 now I declare my HWND in my main.cpp and get the error in init.cpp that it''s not declared, so I declare it in my main.h instead and include my main.h in my main.cpp and init.cpp (I need it in both files) now I get the already defined-error?!? aaaaarrrrgggghhhh can some1 pls help me out here

Share this post


Link to post
Share on other sites
Are you using any "#" directives in your header file to prevent it from being used twice? Since you're including it in both .cpp files, unless you do something to prevent it the compiler will try to include your header code in both files and thus the variable you're declaring will attempt to be declared a second time.

If you're using Visual C++, you can use the #pragma once directive (though I'm not sure that's generally accepted practice).

Or, you can use something like the following:

  
#ifndef MYHEADER_H
#define MYHEADER_H

//put all your header code here


#endif //MYHEADER_H



EDIT: because I didn't use source tags correctly

--Roderick Smith

[edited by - RdrckSmith on June 25, 2002 2:37:43 PM]

Share this post


Link to post
Share on other sites
I think its out of scope because u declared it inside the winmain function. When u declare ure HWND, declare it outside of any function so that it is global.

Share this post


Link to post
Share on other sites
Try passing your HWND as a parameter to whatever function needs it.

Example:

void Function(HWND hWnd)
{
//Stuff
};


Then when you call it, you would put:

Function(hWnd);

That should work.


Share this post


Link to post
Share on other sites
Palidine''s method is the correct way to share globals across multiple files.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/

Share this post


Link to post
Share on other sites