Base struct instead of class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ron Natalie

    #16
    Re: Base struct instead of class


    "White Wolf" <wolof@freemail .hu> wrote in message news:bjenr4$o7t $1@phys-news1.kolumbus. fi...
    [color=blue]
    > First: *all* of your classes *must* have a virtual destructor. They all
    > have virtual functions. Especially hashable and runnable *must* have
    > virtual destructors.[/color]

    Not necessarily true. Do not confuse "rules of thumb" with the MUST rules
    of the language. The only time you need a virtual destructor is when derived
    classes are deleted through pointers of their base types.


    Comment

    • Mike Smith

      #17
      Re: Base struct instead of class

      Alf P. Steinbach wrote:[color=blue]
      >
      > Thanks, and please pass the word (it's September again).[/color]

      Isn't it always? ;-)

      --
      Mike Smith

      Comment

      • Mike Smith

        #18
        Re: Base struct instead of class

        Ivan Vecerina wrote:[color=blue]
        >
        > As Thomas mentioned, this only saves you from having to add
        > a 'public:' specification. Except for the public access
        > specifications, all uses of keyword 'struct' can be relaced
        > by 'class' in C++.[/color]

        Or vice versa - one could argue that the "class" keyword was never
        necessary at all, whereas "struct", of course, was already pre-existing
        in C.

        --
        Mike Smith


        Comment

        • Dave Theese

          #19
          Re: Base struct instead of class

          [color=blue][color=green]
          > > As Thomas mentioned, this only saves you from having to add
          > > a 'public:' specification. Except for the public access
          > > specifications, all uses of keyword 'struct' can be relaced
          > > by 'class' in C++.[/color][/color]

          Actually, there is one other thing to look out for...

          When inheriting, if you don't specify public, inherited or private, the
          default will be different depending on whether you inherit from a struct or
          class. When inheriting from a struct, it will be public inheritance; when
          inheriting from a class, it will be private inheritance.

          So, if you replaced all "struct"s with "class"es and added "public" access
          specifications as necessary to make all access rights equivalent to what
          they were before, it is still possible for the meaning of a program to
          change. Specifically, some public inheritance might change to private
          inheritance, as stated above...



          Comment

          • jeffc

            #20
            Re: Base struct instead of class


            "Mike Smith" <mike_UNDERSCOR E_smith@acm.DOT .org> wrote in message
            news:vls8iofm75 sg39@news.super news.com...[color=blue]
            >
            > Or vice versa - one could argue that the "class" keyword was never
            > necessary at all, whereas "struct", of course, was already pre-existing
            > in C.[/color]

            Or, since the meaning of struct has changed from C, one could argue that
            struct shouldn't do anything different from what it did in C, but only the
            new keyword class should be used to implement classes.


            Comment

            • Ron Natalie

              #21
              Re: Base struct instead of class

              Dave Theese wrote:
              [color=blue]
              >
              > When inheriting, if you don't specify public, inherited or private, the
              > default will be different depending on whether you inherit from a struct or
              > class. When inheriting from a struct, it will be public inheritance; when
              > inheriting from a class, it will be private inheritance.[/color]

              No, it doesn't work that way. It doesn't matter whether the class you are
              inheritting from was defined with struct or class. What matters is the key
              used to define the derived class.

              struct X; // or class X; it doesn't matter

              struct Y : X { } ; // Public inheritance
              class Y : X { } ; // Private inheritance.
              [color=blue]
              >
              > So, if you replaced all "struct"s with "class"es and added "public" access
              > specifications as necessary to make all access rights equivalent to what
              > they were before, it is still possible for the meaning of a program to
              > change. Specifically, some public inheritance might change to private
              > inheritance, as stated above...[/color]

              Nope, you just have to make sure you put in enough public keys

              struct Y : X { ...
              is equivielent to
              class Y : public X {
              public: ...




              Comment

              • Default User

                #22
                Re: Base struct instead of class

                Mike Smith wrote:[color=blue]
                >
                > Alf P. Steinbach wrote:[color=green]
                > >
                > > Thanks, and please pass the word (it's September again).[/color]
                >
                > Isn't it always? ;-)[/color]


                Yes, but sometimes it's more September than other times. Like in
                September.




                Brian Rodenborn

                Comment

                • Dave Theese

                  #23
                  Re: Base struct instead of class

                  > > When inheriting, if you don't specify public, inherited or private, the[color=blue][color=green]
                  > > default will be different depending on whether you inherit from a struct[/color][/color]
                  or[color=blue][color=green]
                  > > class. When inheriting from a struct, it will be public inheritance;[/color][/color]
                  when[color=blue][color=green]
                  > > inheriting from a class, it will be private inheritance.[/color]
                  >
                  > No, it doesn't work that way. It doesn't matter whether the class you[/color]
                  are[color=blue]
                  > inheritting from was defined with struct or class. What matters is the[/color]
                  key[color=blue]
                  > used to define the derived class.
                  >
                  > struct X; // or class X; it doesn't matter
                  >
                  > struct Y : X { } ; // Public inheritance
                  > class Y : X { } ; // Private inheritance.
                  >[color=green]
                  > >
                  > > So, if you replaced all "struct"s with "class"es and added "public"[/color][/color]
                  access[color=blue][color=green]
                  > > specifications as necessary to make all access rights equivalent to what
                  > > they were before, it is still possible for the meaning of a program to
                  > > change. Specifically, some public inheritance might change to private
                  > > inheritance, as stated above...[/color]
                  >
                  > Nope, you just have to make sure you put in enough public keys
                  >
                  > struct Y : X { ...
                  > is equivielent to
                  > class Y : public X {
                  > public: ...[/color]

                  Oh geez, you are absolutely right. Public vs. private by default depends on
                  the derived class, not the base class. 11.2.2 spells this out...

                  Thx for setting it straight!



                  Comment

                  Working...