Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. confusing problem

confusing problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++visual-studiohelp
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    swatgodjr
    wrote on last edited by
    #1

    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.

    C P S 3 Replies Last reply
    0
    • S swatgodjr

      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.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      S 1 Reply Last reply
      0
      • S swatgodjr

        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.

        P Offline
        P Offline
        Phil J Pearson
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • C Christian Graus

          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 )

          S Offline
          S Offline
          swatgodjr
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • S swatgodjr

            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.

            S Offline
            S Offline
            Sameerkumar Namdeo
            wrote on last edited by
            #5

            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.

            S 1 Reply Last reply
            0
            • S Sameerkumar Namdeo

              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.

              S Offline
              S Offline
              swatgodjr
              wrote on last edited by
              #6

              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.

              S 1 Reply Last reply
              0
              • S swatgodjr

                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.

                S Offline
                S Offline
                Sameerkumar Namdeo
                wrote on last edited by
                #7

                just paste the code of the headers in which you have declared th variables.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups