confusing problem
-
hi, i have created a program that uses several different header files and to make it easy for all header files to access stuff i had all my cpp files just reference 1 file that includes all my header files. all of the files compile fine except 1 which complains about a undeclared variable that is part of one of my classes but what makes no sense is that that source file sees my class with that variable in it just fine and intellisense shows the class variable that is supposedly undeclared. thanks in advance for any advice anyone can give me.
-
hi, i have created a program that uses several different header files and to make it easy for all header files to access stuff i had all my cpp files just reference 1 file that includes all my header files. all of the files compile fine except 1 which complains about a undeclared variable that is part of one of my classes but what makes no sense is that that source file sees my class with that variable in it just fine and intellisense shows the class variable that is supposedly undeclared. thanks in advance for any advice anyone can give me.
Sounds like we need to see the code.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
hi, i have created a program that uses several different header files and to make it easy for all header files to access stuff i had all my cpp files just reference 1 file that includes all my header files. all of the files compile fine except 1 which complains about a undeclared variable that is part of one of my classes but what makes no sense is that that source file sees my class with that variable in it just fine and intellisense shows the class variable that is supposedly undeclared. thanks in advance for any advice anyone can give me.
You probably need to understand the difference between declared and defined. declaring a variable tells the compiler that such a variable exists somewhere [else]. defining a variable causes the variable to exist. This is somewhat of a simplification for the sake of a quick answer You may be seeing an undefined variable error for a variable that is declared in your header file; that is, you told the compiler that the variable exists but it doesn't exist. Compilers (and linkers) don't like being lied to. ;)
Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
-
Sounds like we need to see the code.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
here is the function that has the problem:
typedef void (*MYPROC)(LPTSTR); MYPROC ProcAdd; BOOL fRunTimeLinkSuccess; Load *a; Loader *b; a->Hide(load_window); b->Hide(loader_window); hinstLib = LoadLibrary(program); if(hinstLib != NULL) { ProcAdd = (MYPROC)GetProcAddress(hinstLib, "?prog_start@@YAHXZ"); if(fRunTimeLinkSuccess = (ProcAdd != NULL)) { (ProcAdd)("?prog_start@@YAHXZ"); } else{ MessageBox(m_hWnd, "Program Failed to Load", "Fail", MB_ICONSTOP); EndDialog(m_hWnd, IDOK); } } else{ MessageBox(m_hWnd, "Loader Failed to open program", "Fail", MB_ICONSTOP); reportError(); } fFreeResult = FreeLibrary(hinstLib); b->Show(loader_window); a->Show(load_window);
not exactly the best way to load a dll file but it works for what i was doing right now to test stuff with. loader_window is the one that can not be seen, it is a hwnd variable to one of the windows in my program. and here is the code where i have everything being included:#ifndef MAIN_H #define MAIN_H #include #include #include "..\common\win32.h" #include "resource.h" #include "loader.h" #include "load.h" #include "help.h" #include "version.h" #endif
-
hi, i have created a program that uses several different header files and to make it easy for all header files to access stuff i had all my cpp files just reference 1 file that includes all my header files. all of the files compile fine except 1 which complains about a undeclared variable that is part of one of my classes but what makes no sense is that that source file sees my class with that variable in it just fine and intellisense shows the class variable that is supposedly undeclared. thanks in advance for any advice anyone can give me.
where this "loader_window" is declared? It should be declared as a global variable, if you want to use it in the code you posted. Check the variable's scope.
-
where this "loader_window" is declared? It should be declared as a global variable, if you want to use it in the code you posted. Check the variable's scope.
well i had it as global but because of how my code is set up, i can not really compile the program very easily without having to force the program to be compiled because it will get included more than once and the 15+ warnings it gives got annoying to look at and unless i do force it to compile than it will register as errors instead.
-
well i had it as global but because of how my code is set up, i can not really compile the program very easily without having to force the program to be compiled because it will get included more than once and the 15+ warnings it gives got annoying to look at and unless i do force it to compile than it will register as errors instead.
just paste the code of the headers in which you have declared th variables.