undeclared identifier
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
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:
EDIT: because I didn't use source tags correctly
--Roderick Smith
[edited by - RdrckSmith on June 25, 2002 2:37:43 PM]
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]
--Roderick Smith
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.
in main.h -> declare: extern HWND hWnd
in main.cpp -> declare: HWND hWnd
also as mentioned wrap your main.h in #ifndef...#define....#endif
-me
in main.cpp -> declare: HWND hWnd
also as mentioned wrap your main.h in #ifndef...#define....#endif
-me
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.
Example:
void Function(HWND hWnd)
{
//Stuff
};
Then when you call it, you would put:
Function(hWnd);
That should work.
-------Im not Greedy,Im just generous with myself
Palidine''s method is the correct way to share globals across multiple files.
/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement