structure redefinition problem

Discussion in 'C++' started by Scoots, Jul 3, 2007.

  1. Scoots

    Scoots Guest

    I know the usually applied workaround for multiple definitions of
    header files, but I have a problem on this one.

    This time, I can't just ifndef the header file that defines my
    structure.

    So I have two classes that I've managed to dodge around this problem
    for a while, but now I need the include in both classes. This wasn't
    a problem until now, when I'm trying to declare an stl map with a
    structure as a data type.

    All I need is that structure, I don't need the rest of it. Is there a
    way to extern a structure? Or do a forward declaration? I have the
    include fine in the .c file, but now I want a member variable and I'm
    not sure how to get it there.

    Thanks,
    ~Scoots
     
    Scoots, Jul 3, 2007
    #1
    1. Advertising

  2. Scoots wrote:
    > I know the usually applied workaround for multiple definitions of
    > header files, but I have a problem on this one.
    >
    > This time, I can't just ifndef the header file that defines my
    > structure.
    >
    > So I have two classes that I've managed to dodge around this problem
    > for a while, but now I need the include in both classes. This wasn't
    > a problem until now, when I'm trying to declare an stl map with a
    > structure as a data type.
    >
    > All I need is that structure, I don't need the rest of it. Is there a
    > way to extern a structure? Or do a forward declaration? I have the
    > include fine in the .c file, but now I want a member variable and I'm
    > not sure how to get it there.


    Usually, if you need a map of your type, the type has to be completely
    defined, a forward declaration just won't do.

    I am sorry, I can't really grasp what you're saying about managing to
    dodge stuff and knowing the usually applied work-around. Perhaps you
    could just post a distilled version of your code...

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jul 3, 2007
    #2
    1. Advertising

  3. Scoots

    Scoots Guest

    On Jul 3, 10:54 am, "Victor Bazarov" <> wrote:
    > Scoots wrote:
    > > I know the usually applied workaround for multiple definitions of
    > > header files, but I have a problem on this one.

    >
    > > This time, I can't just ifndef the header file that defines my
    > > structure.

    >
    > > So I have two classes that I've managed to dodge around this problem
    > > for a while, but now I need the include in both classes. This wasn't
    > > a problem until now, when I'm trying to declare an stl map with a
    > > structure as a data type.

    >
    > > All I need is that structure, I don't need the rest of it. Is there a
    > > way to extern a structure? Or do a forward declaration? I have the
    > > include fine in the .c file, but now I want a member variable and I'm
    > > not sure how to get it there.

    >
    > Usually, if you need a map of your type, the type has to be completely
    > defined, a forward declaration just won't do.
    >
    > I am sorry, I can't really grasp what you're saying about managing to
    > dodge stuff and knowing the usually applied work-around. Perhaps you
    > could just post a distilled version of your code...
    >
    > V
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask- Hide quoted text -
    >
    > - Show quoted text -


    Yeah, sorry, I knew at the time it was vague but I couldn't find my
    definition. Finally managed to dig it up, and it is not an anonymous
    struct, fortunately. In researching this, I've found references that
    you can't forward declare a typedef'ed anonymous struct, and while
    this is typdef'ed, it isn't anonymous.

    in filea.h (inside of a dll that is included through rt.h)
    typedef struct _CBREQ /* cbr */
    {
    LONG cbIndex;
    LONG cbOffset;
    LONG cbType;
    } CBREQ;


    programwnd.h:
    #include "rt.h" //no real way to move this to programwnd.cpp, same
    dependencies I need in prgengine.h

    class programwnd{

    }

    Prgengine.h:
    #include <map>

    class programwnd; //forward declaration for pointer to "owner"

    class Prgengine{


    private:
    map<string,CBREQ> variableMap
    programwnd *m_masterWnd

    }


    in Prgengine.cpp:

    #include "programwnd.h"
    #include "Prgengine.h"
     
    Scoots, Jul 3, 2007
    #3
  4. Scoots

    Scoots Guest

    On Jul 3, 11:13 am, Scoots <> wrote:
    > On Jul 3, 10:54 am, "Victor Bazarov" <> wrote:
    >
    >
    >
    >
    >
    > > Scoots wrote:
    > > > I know the usually applied workaround for multiple definitions of
    > > > header files, but I have a problem on this one.

    >
    > > > This time, I can't just ifndef the header file that defines my
    > > > structure.

    >
    > > > So I have two classes that I've managed to dodge around this problem
    > > > for a while, but now I need the include in both classes. This wasn't
    > > > a problem until now, when I'm trying to declare an stl map with a
    > > > structure as a data type.

    >
    > > > All I need is that structure, I don't need the rest of it. Is there a
    > > > way to extern a structure? Or do a forward declaration? I have the
    > > > include fine in the .c file, but now I want a member variable and I'm
    > > > not sure how to get it there.

    >
    > > Usually, if you need a map of your type, the type has to be completely
    > > defined, a forward declaration just won't do.

    >
    > > I am sorry, I can't really grasp what you're saying about managing to
    > > dodge stuff and knowing the usually applied work-around. Perhaps you
    > > could just post a distilled version of your code...

    >
    > > V
    > > --
    > > Please remove capital 'A's when replying by e-mail
    > > I do not respond to top-posted replies, please don't ask- Hide quoted text -

    >
    > > - Show quoted text -

    >
    > Yeah, sorry, I knew at the time it was vague but I couldn't find my
    > definition. Finally managed to dig it up, and it is not an anonymous
    > struct, fortunately. In researching this, I've found references that
    > you can't forward declare a typedef'ed anonymous struct, and while
    > this is typdef'ed, it isn't anonymous.
    >
    > in filea.h (inside of a dll that is included through rt.h)
    > typedef struct _CBREQ /* cbr */
    > {
    > LONG cbIndex;
    > LONG cbOffset;
    > LONG cbType;
    >
    > } CBREQ;
    >
    > programwnd.h:
    > #include "rt.h" //no real way to move this to programwnd.cpp, same
    > dependencies I need in prgengine.h
    >
    > class programwnd{
    >
    > }
    >
    > Prgengine.h:
    > #include <map>
    >
    > class programwnd; //forward declaration for pointer to "owner"
    >
    > class Prgengine{
    >
    > private:
    > map<string,CBREQ> variableMap
    > programwnd *m_masterWnd
    >
    > }
    >
    > in Prgengine.cpp:
    >
    > #include "programwnd.h"
    > #include "Prgengine.h"- Hide quoted text -
    >
    > - Show quoted text -


    for debug purposes only I managed to get it to:

    programwnd:
    #include "prgengine.h"


    prgengine.h:
    #include "rtexec2.h"
    class CProgramWnd;
    class Prgengine{
    private:
    map<string,CBREQ> variableMap;
    programwnd *m_masterWnd ;
    }

    prgengine.cpp:
    #include "PrgStackEngine.h"
    #include "programwnd.h"


    which removes the need for forward declaration through nested headers
    (ick), but it works for debugging and getting this going.


    and I get ~20 of about these error messages: Is that a problem?
    c:\program files\microsoft visual studio\vc98\include\xtree(200) :
    warning C4786: '?rbegin@?$_Tree@HU?$pair@$$CBHU_CBREQ@@@std@@U_Kfn@?
    $map@HU_CBREQ@@U?$less@H@std@@V?$allocator@U_CBREQ@@@3@@2@U?
    $less@H@2@V?$allocator@U_CBREQ@@@2@@std@@QAE?AV?$rever
    se_bidirectional_iterator@Viterator@?$_Tree@HU?$pair@$
    $CBHU_CBREQ@@@std@@U_Kfn@?$map@HU_CBREQ@@U?$less@H@std@@V?
    $allocator@U_CBREQ@@@3@@2@U?$less@H@2@V?$allocator@U_CBREQ@@@2@@std@@U?
    $pair@$$CBHU_CBREQ@@@3@AAU43@PAU43@H@2@XZ' : identifier was trunca
    ted to '255' characters in the browser information
     
    Scoots, Jul 3, 2007
    #4
  5. Scoots

    Scoots Guest

    for debug purposes only I managed to get it to:

    programwnd:
    #include "prgengine.h"


    prgengine.h:
    #include "rtexec2.h"
    class CProgramWnd;
    class Prgengine{
    private:
    map<string,CBREQ> variableMap;
    programwnd *m_masterWnd ;



    }


    prgengine.cpp:
    #include "PrgStackEngine.h"
    #include "programwnd.h"

    which removes the need for forward declaration through nested headers
    (ick), but it works for debugging and getting this going. So the
    solution isn't urgent, for now I'll be able to continue coding, but I
    would appreciate any insight you have in getting rid of this nested
    header dependency.


    and I get ~20 of about these error messages: but that's vs 6.0
    specific.
    c:\program files\microsoft visual studio\vc98\include\xtree(200) :
    warning C4786: '?rbegin@?$_Tree@HU?$pair@$$CBHU_CBREQ@@@std@@U_Kfn@?
    $map@HU_CBREQ@@U?$less@H@std@@V?$allocator@U_CBREQ@@@3@@2@U?
    $less@H@2@V?$allocator@U_CBREQ@@@2@@std@@QAE?AV?$rever
    se_bidirectional_iterator@Viterator@?$_Tree@HU?$pair@$
    $CBHU_CBREQ@@@std@@U_Kfn@?$map@HU_CBREQ@@U?$less@H@std@@V?
    $allocator@U_CBREQ@@@3@@2@U?$less@H@2@V?
    $allocator@U_CBREQ@@@2@@std@@U?
    $pair@$$CBHU_CBREQ@@@3@AAU43@PAU43@H@2@XZ' : identifier was trunca
    ted to '255' characters in the browser information
     
    Scoots, Jul 3, 2007
    #5
  6. Scoots wrote:
    > for debug purposes only I managed to get it to:
    >
    > programwnd:
    > #include "prgengine.h"
    >
    >
    > prgengine.h:
    > #include "rtexec2.h"
    > class CProgramWnd;
    > class Prgengine{
    > private:
    > map<string,CBREQ> variableMap;
    > programwnd *m_masterWnd ;
    >
    >
    >
    > }
    >
    >
    > prgengine.cpp:
    > #include "PrgStackEngine.h"
    > #include "programwnd.h"
    >
    > which removes the need for forward declaration through nested headers
    > (ick), but it works for debugging and getting this going. So the
    > solution isn't urgent, for now I'll be able to continue coding, but I
    > would appreciate any insight you have in getting rid of this nested
    > header dependency.
    >
    >
    > and I get ~20 of about these error messages: but that's vs 6.0
    > specific.


    Did you read them? They are not _error_ messages. They are *warnings*.
    Ignore them.

    > c:\program files\microsoft visual studio\vc98\include\xtree(200) :
    > warning C4786: '?rbegin@?$_Tree@HU?$pair@$$CBHU_CBREQ@@@std@@U_Kfn@?
    > $map@HU_CBREQ@@U?$less@H@std@@V?$allocator@U_CBREQ@@@3@@2@U?
    > $less@H@2@V?$allocator@U_CBREQ@@@2@@std@@QAE?AV?$rever
    > se_bidirectional_iterator@Viterator@?$_Tree@HU?$pair@$
    > $CBHU_CBREQ@@@std@@U_Kfn@?$map@HU_CBREQ@@U?$less@H@std@@V?
    > $allocator@U_CBREQ@@@3@@2@U?$less@H@2@V?
    > $allocator@U_CBREQ@@@2@@std@@U?
    > $pair@$$CBHU_CBREQ@@@3@AAU43@PAU43@H@2@XZ' : identifier was trunca
    > ted to '255' characters in the browser information


    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jul 3, 2007
    #6
  7. On 2007-07-03 17:13, Scoots wrote:
    > On Jul 3, 10:54 am, "Victor Bazarov" <> wrote:
    >> Scoots wrote:
    >> > I know the usually applied workaround for multiple definitions of
    >> > header files, but I have a problem on this one.

    >>
    >> > This time, I can't just ifndef the header file that defines my
    >> > structure.

    >>
    >> > So I have two classes that I've managed to dodge around this problem
    >> > for a while, but now I need the include in both classes. This wasn't
    >> > a problem until now, when I'm trying to declare an stl map with a
    >> > structure as a data type.

    >>
    >> > All I need is that structure, I don't need the rest of it. Is there a
    >> > way to extern a structure? Or do a forward declaration? I have the
    >> > include fine in the .c file, but now I want a member variable and I'm
    >> > not sure how to get it there.

    >>
    >> Usually, if you need a map of your type, the type has to be completely
    >> defined, a forward declaration just won't do.
    >>
    >> I am sorry, I can't really grasp what you're saying about managing to
    >> dodge stuff and knowing the usually applied work-around. Perhaps you
    >> could just post a distilled version of your code...
    >>

    >
    > Yeah, sorry, I knew at the time it was vague but I couldn't find my
    > definition. Finally managed to dig it up, and it is not an anonymous
    > struct, fortunately. In researching this, I've found references that
    > you can't forward declare a typedef'ed anonymous struct, and while
    > this is typdef'ed, it isn't anonymous.
    >
    > in filea.h (inside of a dll that is included through rt.h)
    > typedef struct _CBREQ /* cbr */
    > {
    > LONG cbIndex;
    > LONG cbOffset;
    > LONG cbType;
    > } CBREQ;


    Not related to your problem but unless you have to maintain
    compatibility with C you don't need the typedef, just

    struct CBREQ {
    // ...
    };

    will do. And when I'm at it, all-caps identifiers are generally reserved
    for macros.

    --
    Erik Wikström
     
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=, Jul 3, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Attila Feher

    Template redefinition problem

    Attila Feher, Sep 22, 2003, in forum: C++
    Replies:
    5
    Views:
    2,231
    tom_usenet
    Sep 22, 2003
  2. Alex
    Replies:
    1
    Views:
    556
    mlimber
    Jul 19, 2006
  3. Replies:
    1
    Views:
    409
    Victor Bazarov
    Jul 26, 2006
  4. dust
    Replies:
    7
    Views:
    1,039
  5. Leslie Viljoen

    Array redefinition problem

    Leslie Viljoen, Aug 12, 2005, in forum: Ruby
    Replies:
    12
    Views:
    230
    Pit Capitain
    Aug 13, 2005
Loading...

Share This Page