CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1

    redefinition of xxx ignored



    A very simple question of all, I think. But no idea myself :-(

    I have written a cpp-prg which´s source is getting too long now. I have build modules of it and included the necessary .hpp - files in each module. During compilation all is ok, but when the linker starts it bombs me with hundreds of "redefinition of xxx ignored in xxx". This are only warnings, no errors, and the linked prg is ok. Reduciong the warning - level does not change anything. It is not a really problem, but I want to kill this warning - list. If I build a new .hpp - file for each module, I must define each variable with "extern unsigned long..." once more, so that changing of one variable takes changing of 20 .hpp - files.

    What must I do?

  2. #2
    Join Date
    Mar 1999
    Posts
    2

    Re: redefinition of xxx ignored



    Hello Andreas,


    if you have defined a variable, say int i as global in one module, then you cannot define it again in another module. You should define it external, that's the reason for the warnings. You can define a compiler variable in your main module like this:


    #define MAIN


    Then you can change your hpp files as follow to define your global variables:


    #ifdef MAIN

    int i;

    #else

    extern int i;

    #endif


    Then you just need to change the hpp-file.


    Greetings

    Wing.

  3. #3
    Join Date
    Apr 1999
    Posts
    191

    C++ Lecture



    Now might be a good time to re-think your overall design. There is one school of object oriented thought that says you should try to avoid globals. Of course, it would take a while to fix your problem, but you might be saving yourself from future woes.

  4. #4
    Join Date
    May 1999
    Location
    Oregon, USA
    Posts
    302

    Re: redefinition of xxx ignored



    Mr. Bore has a very valid point - the use of global data should

    be minimized. When I need globals I use a variation of Wing's

    approach. In a header somewhere do this :


    #ifndef GLOBAL

    #ifdef MAIN

    #define GLOBAL

    #else // MAIN

    #define GLOBAL extern

    #endif // MAIN

    #endif // GLOBAL


    Then when you declare a variable that will be global do this :


    GLOBAL MyGlobalData MyData;


    Then, in one and ONLY one module, typically the CWinApp derivation

    module, define MAIN before including the header with the globals :


    #define MAIN

    #include "header.h"


    This will work for nearly any kind of data including the

    application object.



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