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. variable problem

variable problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    How can I solve the probelm with the following error message: "variable" already defined in GO.obj

    J 1 Reply Last reply
    0
    • A Anonymous

      How can I solve the probelm with the following error message: "variable" already defined in GO.obj

      J Offline
      J Offline
      jmkhael
      wrote on last edited by
      #2

      This means that you defined "variable" in more than a file, and both defines it as public If each one should have its copy, try putting static in front of them If the variable should be shared, declare it as extern in one of the files Papa while (TRUE) Papa.WillLove ( Bebe ) ;

      A 1 Reply Last reply
      0
      • J jmkhael

        This means that you defined "variable" in more than a file, and both defines it as public If each one should have its copy, try putting static in front of them If the variable should be shared, declare it as extern in one of the files Papa while (TRUE) Papa.WillLove ( Bebe ) ;

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        I have added extern to the variables with the error message and the problem is solved. Thanks! But i only declare them in one file. Why does the problem occur? my project name is go and i declare the variables in go.h just below #define... (as global)

        D J 2 Replies Last reply
        0
        • A Anonymous

          I have added extern to the variables with the error message and the problem is solved. Thanks! But i only declare them in one file. Why does the problem occur? my project name is go and i declare the variables in go.h just below #define... (as global)

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Anonymous wrote: But i only declare them in one file. But that .h file is included in multiple places.


          "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

          1 Reply Last reply
          0
          • A Anonymous

            I have added extern to the variables with the error message and the problem is solved. Thanks! But i only declare them in one file. Why does the problem occur? my project name is go and i declare the variables in go.h just below #define... (as global)

            J Offline
            J Offline
            jmkhael
            wrote on last edited by
            #5

            Can you show how and where are you doing the declaration? Papa while (TRUE) Papa.WillLove ( Bebe ) ;

            A 1 Reply Last reply
            0
            • J jmkhael

              Can you show how and where are you doing the declaration? Papa while (TRUE) Papa.WillLove ( Bebe ) ;

              A Offline
              A Offline
              Anonymous
              wrote on last edited by
              #6

              Its ok now. I know the problem. Thank you very much! :-D in go.h: // GO.h : main header file for the GO application // #if !defined(AFX_GO_H__76EC2730_7BFA_4A29_9F6A_226E7AEC7B81__INCLUDED_) #define AFX_GO_H__76EC2730_7BFA_4A29_9F6A_226E7AEC7B81__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #ifndef __AFXWIN_H__ #error include 'stdafx.h' before including this file for PCH #endif #include "resource.h" // main symbols #define MAX_STEP 1000 #define MAX_FILE_NAME 30 #define BOARD_SIZE 19 #define BLACK '@' #define WHITE 'O' #define KEP '*' #define EMPTY '.' #define EMPTY_STAR '+' #define CHECKED_LAND 'C' #define BLACK_LAND 'b' #define WHITE_LAND 'w' #define SHARED_LAND ' ' struct step_record { char command; int row; int col; }; // global variables: static char boardc[BOARD_SIZE][BOARD_SIZE]; static char turn; static int kep_row, kep_col; static int black_eaten, white_eaten; static int step_num, last_step_num; static bool remove_dead_chess; static bool count; static float black_land, white_land; static struct step_record step[MAX_STEP+1]; ///////////////////////////////////////////////////////////////////////////// // CGOApp: // See GO.cpp for the implementation of this class // class CGOApp : public CWinApp { public: ...

              B 1 Reply Last reply
              0
              • A Anonymous

                Its ok now. I know the problem. Thank you very much! :-D in go.h: // GO.h : main header file for the GO application // #if !defined(AFX_GO_H__76EC2730_7BFA_4A29_9F6A_226E7AEC7B81__INCLUDED_) #define AFX_GO_H__76EC2730_7BFA_4A29_9F6A_226E7AEC7B81__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #ifndef __AFXWIN_H__ #error include 'stdafx.h' before including this file for PCH #endif #include "resource.h" // main symbols #define MAX_STEP 1000 #define MAX_FILE_NAME 30 #define BOARD_SIZE 19 #define BLACK '@' #define WHITE 'O' #define KEP '*' #define EMPTY '.' #define EMPTY_STAR '+' #define CHECKED_LAND 'C' #define BLACK_LAND 'b' #define WHITE_LAND 'w' #define SHARED_LAND ' ' struct step_record { char command; int row; int col; }; // global variables: static char boardc[BOARD_SIZE][BOARD_SIZE]; static char turn; static int kep_row, kep_col; static int black_eaten, white_eaten; static int step_num, last_step_num; static bool remove_dead_chess; static bool count; static float black_land, white_land; static struct step_record step[MAX_STEP+1]; ///////////////////////////////////////////////////////////////////////////// // CGOApp: // See GO.cpp for the implementation of this class // class CGOApp : public CWinApp { public: ...

                B Offline
                B Offline
                Bob Stanneveld
                wrote on last edited by
                #7

                Anonymous wrote: // global variables: static char boardc[BOARD_SIZE][BOARD_SIZE]; static char turn; static int kep_row, kep_col; static int black_eaten, white_eaten; static int step_num, last_step_num; static bool remove_dead_chess; static bool count; static float black_land, white_land; static struct step_record step[MAX_STEP+1]; This is wrong! I believe that you want one variable that is shared among all the components of your application. The current situation is that each object file (component) has its own copy of the variable. So if you execute the following statement in GoApp.cpp:turn = (char)100 the change is only seen in GoApp.cpp, so in GoView.cpp, the variable turn is still undefined! Try the following instead: // Go.cpp // global variables: char boardc[BOARD_SIZE][BOARD_SIZE]; char turn; extern int kep_row, kep_col; extern int black_eaten, white_eaten; extern int step_num, last_step_num; extern bool remove_dead_chess; extern bool count; extern float black_land, white_land; extern struct step_record step[MAX_STEP+1]; // Go.h // global variables: extern char boardc[BOARD_SIZE][BOARD_SIZE]; extern char turn; int kep_row, kep_col; int black_eaten, white_eaten; int step_num, last_step_num; bool remove_dead_chess; bool count; float black_land, white_land; struct step_record step[MAX_STEP+1]; This way, the value of the variables is the always the same in every component.. Blog[^]

                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