CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    Join Date
    Aug 2011
    Posts
    13

    Re: What is wrong with my code organization?

    Unfortunately I am still having the same errors. I will collapse all of my functions and post my project since nothing seems to be helping.

  2. #17
    Join Date
    Aug 2011
    Posts
    13

    Re: What is wrong with my code organization?

    I attached screenshots of config.h, image.h and objects.h since copy paste still includes collapsed text.

    error log:
    Code:
    ------ Rebuild All started: Project: Swordfight, Configuration: Debug Win32 ------
    Deleting intermediate and output files for project 'Swordfight', configuration 'Debug|Win32'
    Compiling...
    swordfight.cpp
    c:\visual studio\swordfight\swordfight\swordfight\config.h(21) : error C2065: 'handles' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\config.h(21) : error C2228: left of '.hwnd' must have class/struct/union
            type is ''unknown-type''
    c:\visual studio\swordfight\swordfight\swordfight\config.h(23) : error C2065: 'handles' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\config.h(23) : error C2228: left of '.hwnd' must have class/struct/union
            type is ''unknown-type''
    c:\visual studio\swordfight\swordfight\swordfight\config.h(41) : error C2065: 'settings' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\config.h(41) : error C2228: left of '.executable' must have class/struct/union
            type is ''unknown-type''
    c:\visual studio\swordfight\swordfight\swordfight\config.h(44) : error C2065: 'handles' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\config.h(44) : error C2228: left of '.hwnd' must have class/struct/union
            type is ''unknown-type''
    c:\visual studio\swordfight\swordfight\swordfight\config.h(49) : error C2065: 'handles' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\config.h(49) : error C2228: left of '.hwnd' must have class/struct/union
            type is ''unknown-type''
    c:\visual studio\swordfight\swordfight\swordfight\config.h(51) : error C2065: 'handles' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\config.h(51) : error C2228: left of '.hwnd' must have class/struct/union
            type is ''unknown-type''
    c:\visual studio\swordfight\swordfight\swordfight\config.h(52) : error C2065: 'settings' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\config.h(52) : error C2228: left of '.pixels_x' must have class/struct/union
            type is ''unknown-type''
    c:\visual studio\swordfight\swordfight\swordfight\config.h(58) : error C2065: 'handles' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\config.h(58) : error C2228: left of '.hwnd' must have class/struct/union
            type is ''unknown-type''
    c:\visual studio\swordfight\swordfight\swordfight\config.h(60) : error C2065: 'handles' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\config.h(60) : error C2228: left of '.hwnd' must have class/struct/union
            type is ''unknown-type''
    c:\visual studio\swordfight\swordfight\swordfight\config.h(61) : error C2065: 'settings' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\config.h(61) : error C2228: left of '.pixels_y' must have class/struct/union
            type is ''unknown-type''
    c:\visual studio\swordfight\swordfight\swordfight\config.h(67) : error C2065: 'handles' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\config.h(67) : error C2228: left of '.hwnd' must have class/struct/union
            type is ''unknown-type''
    c:\visual studio\swordfight\swordfight\swordfight\config.h(68) : error C2065: 'settings' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\config.h(68) : error C2228: left of '.colors' must have class/struct/union
            type is ''unknown-type''
    c:\visual studio\swordfight\swordfight\swordfight\config.h(184) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
    c:\visual studio\swordfight\swordfight\swordfight\image.h(11) : error C2065: 'snip' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(11) : error C2228: left of '.height' must have class/struct/union
            type is ''unknown-type''
    c:\visual studio\swordfight\swordfight\swordfight\image.h(12) : error C2065: 'snip' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(12) : error C2228: left of '.width' must have class/struct/union
            type is ''unknown-type''
    c:\visual studio\swordfight\swordfight\swordfight\image.h(15) : error C2065: 'Previous' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(15) : error C2065: 'Actual' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(16) : error C2065: 'Previous' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(16) : error C2065: 'Actual' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(19) : error C2065: 'Square' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(19) : error C2065: 'Previous' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(19) : error C2228: left of '.me_y' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(19) : error C2065: 'Previous' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(19) : error C2228: left of '.me_y' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(21) : error C2228: left of '.top' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(21) : error C2059: syntax error : ')'
    c:\visual studio\swordfight\swordfight\swordfight\image.h(27) : error C2065: 'y' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(27) : error C2065: 'y' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(27) : error C2065: 'y' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(29) : error C2065: 'x' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(29) : error C2065: 'x' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(29) : error C2065: 'x' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(32) : error C2065: 'Square' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(32) : error C2065: 'y' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(32) : error C2065: 'x' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(32) : error C2228: left of '.status' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(32) : error C2065: 'Square' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(32) : error C2065: 'y' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(32) : error C2065: 'x' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(32) : error C2228: left of '.neighbors' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(35) : error C2065: 'Square' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(35) : error C2065: 'y' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(35) : error C2065: 'x' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(35) : error C2228: left of '.status' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(35) : error C2065: 'Piece' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(35) : error C2065: 'THIS_TURN' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(35) : error C2228: left of '.bottom' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(38) : error C2065: 'Piece' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(38) : error C2065: 'THIS_TURN' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(38) : error C2228: left of '.bottom' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(38) : error C2065: 'Piece' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(38) : error C2065: 'THIS_TURN' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(38) : error C2228: left of '.top' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(43) : error C2065: 'Square' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(43) : error C2065: 'y' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(43) : error C2065: 'x' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(43) : error C2228: left of '.neighbor' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(43) : error C2065: 'Piece' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(43) : error C2065: 'THIS_TURN' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(43) : error C2228: left of '.bottom' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(47) : error C2065: 'Desired' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(47) : error C2228: left of '.me_y' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(47) : error C2065: 'Desired' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(47) : error C2228: left of '.me_y' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(53) : error C2065: 'Desired' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(53) : error C2228: left of '.me_y' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(53) : error C2065: 'Desired' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(53) : error C2228: left of '.me_y' must have class/struct/union
    c:\visual studio\swordfight\swordfight\swordfight\image.h(55) : error C2065: 'Actual' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(55) : error C2065: 'Square' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(55) : error C2065: 'y' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(55) : error C2065: 'x' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(56) : error C2065: 'Actual' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(56) : error C2065: 'Square' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(56) : error C2065: 'y' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(56) : error C2065: 'x' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(57) : error C2143: syntax error : missing ';' before 'return'
    c:\visual studio\swordfight\swordfight\swordfight\image.h(60) : error C2065: 'Actual' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(60) : error C2065: 'Square' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(60) : error C2065: 'y' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(60) : error C2065: 'x' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(61) : error C2065: 'Actual' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(61) : error C2065: 'Square' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(61) : error C2065: 'y' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(61) : error C2065: 'x' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(62) : error C2143: syntax error : missing ';' before 'return'
    c:\visual studio\swordfight\swordfight\swordfight\image.h(66) : error C2065: 'Square' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(66) : error C2065: 'y' : undeclared identifier
    c:\visual studio\swordfight\swordfight\swordfight\image.h(66) : fatal error C1003: error count exceeds 100; stopping compilation
    Build log was saved at "file://c:\Visual Studio\Swordfight\Swordfight\Swordfight\Debug\BuildLog.htm"
    Swordfight - 102 error(s), 1 warning(s)
    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
    Attached Images Attached Images    

  3. #18
    Join Date
    Apr 1999
    Posts
    27,449

    Re: What is wrong with my code organization?

    Quote Originally Posted by notinasia View Post
    I see. I combined the advice from you with the advice from stackoverflow..

    While I'm fixing this.. will the following with initial values also work correctly?

    Code:
    EXTERN int i = 0;
    EXTERN myclass its_mine(/* constructor arguments */);
    Unfortunately no. That's why you should refrain from global variables when creating a C++ program.

    Honestly, you would be better if you just created a class or struct with static data members. At the very least, that would be much easier to handle then "old C-style" global variables. You would see most, if not all of these problems disappear.

    Regards,

    Paul McKenzie

  4. #19
    Join Date
    Apr 1999
    Posts
    27,449

    Re: What is wrong with my code organization?

    For example:
    Code:
    #ifndef objects
    #define objects
    
    //#include<vector>
    #include  "swordfight.h"
    #include "object_functions.h"
    #include <windows.h>
    #include "resources.h"
    #include <vector>
    #include "image.h"
    
    class handles_o
    {
        HWND hwnd; // Process handle
        HIMAGELIST imagelist; // Imagelist handle
    };
    
    class settings_o
    {
    	settings_o() {executable =DE1; pixels_x = DE2; pixels_y = DE3; colors = DE4;}
        string executable;
        int pixels_x;
        int pixels_y;
        char colors;
    };
    
    class Pieces
    {
    public:
    	char bottom;
    	char top;
    };
    
    class state_o
    {
    public:
    	void SetPlay(char p){ play = p;}
    	bool GetPlay(){ return play==1;}
    	void toggle_play() {play = !play & detect;}
    	state_o(char p, char d, char v, char dt, char f, char w)
    	{
    		play = p; detect = d; valid = v; detectsf = dt; first = f; win = w; fail = 0;
    	}
        char play;
        char detect;
        char valid;
        char detectsf;
    	char first;	
    	char win;
    	char fail;
    };
    
    class app_o
    {
    public:
        unsigned int x;
        unsigned int y;
        HWND hwnd;
    	DWORD pid;
    	HDC dc;
    	RECT play_rect;	// play area
    	RECT next_rect;	// next piece area
    	RECT sb1_rect;	// score board 1 area 
    	RECT sb2_rect;	// score board 2
    };
    
    struct GlobalData
    {
       static handles_o handles;
       static settings_o settings;
       static Pieces Piece[2];
       static state_o state;
       static app_o app;
    };
    
    #define P_THIS 0
    #define P_NEXT 1
    
    #define CW 0
    #define CCW 1
    
    #endif
    Then in your main module is where you initialize your static members:
    Code:
    // main.cpp
    #include "objects.h"
    //...
       
    handles_o GlobalData::handles;
    settings_o GlobalData::settings;
    Pieces GlobalData::Piece[2] = { whatever };
    state_o GlobalData::state;
    app_o GlobalData::app;
    
    
    int main()
    {
        //... whatever
    }
    Regards,

    Paul McKenzie

  5. #20
    Join Date
    Aug 2011
    Posts
    13

    Re: What is wrong with my code organization?

    So I'm not really making any progress on these linking problems, I'm considering just placing everything in 2-3 fat .h file so there's less room for linking problems...

  6. #21
    Join Date
    Aug 2011
    Posts
    13

    Re: What is wrong with my code organization?

    The globaldata struct looks like another interesting idea, it would take a lot of time to add GlobalData. in front of everything at this point though.

  7. #22
    Join Date
    Apr 1999
    Posts
    27,449

    Re: What is wrong with my code organization?

    Quote Originally Posted by notinasia View Post
    The globaldata struct looks like another interesting idea, it would take a lot of time to add GlobalData. in front of everything at this point though.
    If I could get a dollar for every time I hear this, I would be a rich man.

    I have dealt with code bases that are tens of thousands of lines of C++. When a global change needed to be made, it took me at most, a half-day, if that long to make the changes. What you do is this -- get rid of all of those global variables in your header file. Create the struct. Recompile your code. Fix the compiler errors. Done.

    You will be surprised that this does not take a long time (not days, weeks, or months, maybe hours and sometimes minutes).

    Also, the struct is one way to cut down on the number of globals, even 'C' programmers use this technique to bundle the globals in one place instead of having tons of global variables all over the code.



    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; June 12th, 2012 at 07:38 PM.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured