abstract structs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dirk Reske

    #1

    abstract structs

    hello,

    I have following problem:

    I have a struct "MainStruct "
    now I want to build structs which all "starts" with MainStruct.

    struct1
    {
    MainStruct var;
    anotherStruct var2;
    }

    struct2
    {
    MainStruct var;
    AnotherStruct2 var2;
    }

    ......is there a way to do this?
    And how can I declare a method, which accepts all structs which a derived
    from MainStruct as argument?

    I hope you have understood all (I'm from Germany)


  • codymanix

    #2
    Re: abstract structs

    > I have a struct "MainStruct "[color=blue]
    > now I want to build structs which all "starts" with MainStruct.
    >
    > struct1
    > {
    > MainStruct var;
    > anotherStruct var2;
    > }
    >
    > struct2
    > {
    > MainStruct var;
    > AnotherStruct2 var2;
    > }
    >
    > .....is there a way to do this?
    > And how can I declare a method, which accepts all structs which a derived
    > from MainStruct as argument?[/color]

    It doesn't work this way. You could reach what you want using inheritance
    but structs doesn't support inheritance you should use a class instead.
    [color=blue]
    > I hope you have understood all (I'm from Germany)[/color]

    Ich denk' schon :)

    --
    cody

    [Freeware, Games and Humor]
    www.deutronium.de.vu || www.deutronium.tk


    Comment

    • Dirk Reske

      #3
      Re: abstract structs

      lol....sind doch ganz schön viele deutsche drin:-)
      hatt ich schon oft

      "codymanix" <dont.spam.me.d eutronium@gmx.d e> schrieb im Newsbeitrag
      news:#wFNZJAnDH A.2244@TK2MSFTN GP12.phx.gbl...[color=blue][color=green]
      > > I have a struct "MainStruct "
      > > now I want to build structs which all "starts" with MainStruct.
      > >
      > > struct1
      > > {
      > > MainStruct var;
      > > anotherStruct var2;
      > > }
      > >
      > > struct2
      > > {
      > > MainStruct var;
      > > AnotherStruct2 var2;
      > > }
      > >
      > > .....is there a way to do this?
      > > And how can I declare a method, which accepts all structs which a[/color][/color]
      derived[color=blue][color=green]
      > > from MainStruct as argument?[/color]
      >
      > It doesn't work this way. You could reach what you want using inheritance
      > but structs doesn't support inheritance you should use a class instead.
      >[color=green]
      > > I hope you have understood all (I'm from Germany)[/color]
      >
      > Ich denk' schon :)
      >
      > --
      > cody
      >
      > [Freeware, Games and Humor]
      > www.deutronium.de.vu || www.deutronium.tk
      >
      >[/color]


      Comment

      • Dirk Reske

        #4
        Re: abstract structs

        but when I do:

        struct1
        {
        ....
        }

        struct2 : struct1
        {
        newMember;
        }

        where in memory are the new mebers?
        behind the members of struct1 or in front of it?
        this is, because its a class I use to P/Invoke a Win32 call.
        I need it so:

        MembersOfBaseCl ass
        MembersOfDerive dClass

        "Dirk Reske" <_Freak-2k@gmx.net> schrieb im Newsbeitrag
        news:eDLyrOAnDH A.1708@TK2MSFTN GP12.phx.gbl...[color=blue]
        > lol....sind doch ganz schön viele deutsche drin:-)
        > hatt ich schon oft
        >
        > "codymanix" <dont.spam.me.d eutronium@gmx.d e> schrieb im Newsbeitrag
        > news:#wFNZJAnDH A.2244@TK2MSFTN GP12.phx.gbl...[color=green][color=darkred]
        > > > I have a struct "MainStruct "
        > > > now I want to build structs which all "starts" with MainStruct.
        > > >
        > > > struct1
        > > > {
        > > > MainStruct var;
        > > > anotherStruct var2;
        > > > }
        > > >
        > > > struct2
        > > > {
        > > > MainStruct var;
        > > > AnotherStruct2 var2;
        > > > }
        > > >
        > > > .....is there a way to do this?
        > > > And how can I declare a method, which accepts all structs which a[/color][/color]
        > derived[color=green][color=darkred]
        > > > from MainStruct as argument?[/color]
        > >
        > > It doesn't work this way. You could reach what you want using[/color][/color]
        inheritance[color=blue][color=green]
        > > but structs doesn't support inheritance you should use a class instead.
        > >[color=darkred]
        > > > I hope you have understood all (I'm from Germany)[/color]
        > >
        > > Ich denk' schon :)
        > >
        > > --
        > > cody
        > >
        > > [Freeware, Games and Humor]
        > > www.deutronium.de.vu || www.deutronium.tk
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • cody

          #5
          Re: abstract structs

          > lol....sind doch ganz schön viele deutsche drin:-)[color=blue]
          > hatt ich schon oft[/color]

          Liegt auch einfach daran das die deutschen newsgroups zum kotzen sind. Wenn
          du keinen Realname verwendest, deine Rechtschreibung nicht perfekt ist oder
          was auch immer, dann wirs du gleich dumm angemacht.

          --
          cody

          [Freeware, Games and Humor]
          www.deutronium.de.vu || www.deutronium.tk


          Comment

          • cody

            #6
            Re: abstract structs

            The new members are always behind the the members of the base-class in
            memory but as already pointed out you have to use classes, not structs.

            The exact position and alignment of the members in memory are not defined
            and should not be of interest for you.

            --
            cody

            [Freeware, Games and Humor]
            www.deutronium.de.vu || www.deutronium.tk

            "Dirk Reske" <_Freak-2k@gmx.net> schrieb im Newsbeitrag
            news:uD5qDdAnDH A.3504@TK2MSFTN GP11.phx.gbl...[color=blue]
            > but when I do:
            >
            > struct1
            > {
            > ...
            > }
            >
            > struct2 : struct1
            > {
            > newMember;
            > }
            >
            > where in memory are the new mebers?
            > behind the members of struct1 or in front of it?
            > this is, because its a class I use to P/Invoke a Win32 call.
            > I need it so:
            >
            > MembersOfBaseCl ass
            > MembersOfDerive dClass
            >
            > "Dirk Reske" <_Freak-2k@gmx.net> schrieb im Newsbeitrag
            > news:eDLyrOAnDH A.1708@TK2MSFTN GP12.phx.gbl...[color=green]
            > > lol....sind doch ganz schön viele deutsche drin:-)
            > > hatt ich schon oft
            > >
            > > "codymanix" <dont.spam.me.d eutronium@gmx.d e> schrieb im Newsbeitrag
            > > news:#wFNZJAnDH A.2244@TK2MSFTN GP12.phx.gbl...[color=darkred]
            > > > > I have a struct "MainStruct "
            > > > > now I want to build structs which all "starts" with MainStruct.
            > > > >
            > > > > struct1
            > > > > {
            > > > > MainStruct var;
            > > > > anotherStruct var2;
            > > > > }
            > > > >
            > > > > struct2
            > > > > {
            > > > > MainStruct var;
            > > > > AnotherStruct2 var2;
            > > > > }
            > > > >
            > > > > .....is there a way to do this?
            > > > > And how can I declare a method, which accepts all structs which a[/color]
            > > derived[color=darkred]
            > > > > from MainStruct as argument?
            > > >
            > > > It doesn't work this way. You could reach what you want using[/color][/color]
            > inheritance[color=green][color=darkred]
            > > > but structs doesn't support inheritance you should use a class[/color][/color][/color]
            instead.[color=blue][color=green][color=darkred]
            > > >
            > > > > I hope you have understood all (I'm from Germany)
            > > >
            > > > Ich denk' schon :)
            > > >
            > > > --
            > > > cody
            > > >
            > > > [Freeware, Games and Humor]
            > > > www.deutronium.de.vu || www.deutronium.tk
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            Working...