Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Difference between C++ Structures and C++ Classes

Difference between C++ Structures and C++ Classes

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
12 Posts 10 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Subramaniam s V

    Hi All, Can anybody tell me the exact "Difference between C++ Structures and C++ Classes". I came to know that, apart from the access specifier Public(Structures) and Private(Classes) there is no other difference. Is that so? In that case why do they have 2 difference entities namely Structure and Classes with similar functionality?? Kindly clarify.

    I Offline
    I Offline
    includeh10
    wrote on last edited by
    #2

    I guess people who created C++ like the name "class".

    1 Reply Last reply
    0
    • S Subramaniam s V

      Hi All, Can anybody tell me the exact "Difference between C++ Structures and C++ Classes". I came to know that, apart from the access specifier Public(Structures) and Private(Classes) there is no other difference. Is that so? In that case why do they have 2 difference entities namely Structure and Classes with similar functionality?? Kindly clarify.

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #3

      Subramaniam s.V. wrote:

      In that case why do they have 2 difference entities namely Structure and Classes with similar functionality?

      'struct' allows for backwards-compatibility with C edit: what about this deserves a '1' vote? -- modified at 15:09 Tuesday 8th August, 2006

      image processing | blogging

      N 1 Reply Last reply
      0
      • C Chris Losinger

        Subramaniam s.V. wrote:

        In that case why do they have 2 difference entities namely Structure and Classes with similar functionality?

        'struct' allows for backwards-compatibility with C edit: what about this deserves a '1' vote? -- modified at 15:09 Tuesday 8th August, 2006

        image processing | blogging

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #4

        Then why class were created?? struct itself is enough ..na?

        nave

        C 1 Reply Last reply
        0
        • S Subramaniam s V

          Hi All, Can anybody tell me the exact "Difference between C++ Structures and C++ Classes". I came to know that, apart from the access specifier Public(Structures) and Private(Classes) there is no other difference. Is that so? In that case why do they have 2 difference entities namely Structure and Classes with similar functionality?? Kindly clarify.

          A Offline
          A Offline
          Amar Sutar
          wrote on last edited by
          #5

          Default inheritance type: a struct entails public inheritance by default whereas a class entails private inheritance. Regards Amar:)

          1 Reply Last reply
          0
          • S Subramaniam s V

            Hi All, Can anybody tell me the exact "Difference between C++ Structures and C++ Classes". I came to know that, apart from the access specifier Public(Structures) and Private(Classes) there is no other difference. Is that so? In that case why do they have 2 difference entities namely Structure and Classes with similar functionality?? Kindly clarify.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #6

            Subramaniam s.V. wrote:

            Can anybody tell me the exact "Difference between C++ Structures and C++ Classes".

            This is discussed in The Design and Evolution of C++.


            "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

            "Judge not by the eye but by the heart." - Native American Proverb

            1 Reply Last reply
            0
            • S Subramaniam s V

              Hi All, Can anybody tell me the exact "Difference between C++ Structures and C++ Classes". I came to know that, apart from the access specifier Public(Structures) and Private(Classes) there is no other difference. Is that so? In that case why do they have 2 difference entities namely Structure and Classes with similar functionality?? Kindly clarify.

              V Offline
              V Offline
              Viorel
              wrote on last edited by
              #7

              About differences. The default protection in case of class is "private", whereas in case of struct it is "public":

              class A
              {
              int a; // a is private
              . . .
              }; 
              
              struct A
              {
              int a; // a is public
              . . .
              }; 
              

              The default inheritance protection in case of class is "private", whereas in case of struct it is "public":

              class B : A // is similar to "class B : private A"
              {
              };
              
              struct B : A // is similar to "struct B : public A"
              {
              };
              

              That’s my opinion about differences.

              1 Reply Last reply
              0
              • N Naveen

                Then why class were created?? struct itself is enough ..na?

                nave

                C Offline
                C Offline
                Chris Losinger
                wrote on last edited by
                #8

                'class' is proper OO terminology, 'struct' isn't. but default member access isn't the only difference between struct and class: you can't use templates on structs - only on classes . a 'class' is intended to be the primary object type. 'struct' is for backwards compatibility. and, yes they overlap .

                image processing | blogging

                N 1 Reply Last reply
                0
                • S Subramaniam s V

                  Hi All, Can anybody tell me the exact "Difference between C++ Structures and C++ Classes". I came to know that, apart from the access specifier Public(Structures) and Private(Classes) there is no other difference. Is that so? In that case why do they have 2 difference entities namely Structure and Classes with similar functionality?? Kindly clarify.

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #9

                  See The difference between structs and classes[^]

                  _**


                  **_

                  WhiteSky


                  1 Reply Last reply
                  0
                  • S Subramaniam s V

                    Hi All, Can anybody tell me the exact "Difference between C++ Structures and C++ Classes". I came to know that, apart from the access specifier Public(Structures) and Private(Classes) there is no other difference. Is that so? In that case why do they have 2 difference entities namely Structure and Classes with similar functionality?? Kindly clarify.

                    Z Offline
                    Z Offline
                    Zac Howland
                    wrote on last edited by
                    #10

                    struct and class in C++ are identical with the exception of their default visibility (private for class, public for struct). The struct keyword was a leftover from the C lineage of C++. That said, when a C++ compiler sees the struct keyword, it will compile it, but not in the same way that a C compiler would have. The C++ compiler will generate a default constructor, destructor, and copy-assignment operator (whereas a C compiler would just treat it as a new datatype). They both exist in C++ because of the desire to be able to compile C code with a C++ compiler. Removing keywords such as this would have made such backwards-compatability impossible without first modifying the codebase.

                    If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                    1 Reply Last reply
                    0
                    • C Chris Losinger

                      'class' is proper OO terminology, 'struct' isn't. but default member access isn't the only difference between struct and class: you can't use templates on structs - only on classes . a 'class' is intended to be the primary object type. 'struct' is for backwards compatibility. and, yes they overlap .

                      image processing | blogging

                      N Offline
                      N Offline
                      Nemanja Trifunovic
                      wrote on last edited by
                      #11

                      Chris Losinger wrote:

                      you can't use templates on structs - only on classes .

                      If you mean you can't use struct keyword inside of a template declaration, you are right. However, it is perfectly possible to make struct templates.

                      Programming Blog utf8-cpp

                      C 1 Reply Last reply
                      0
                      • N Nemanja Trifunovic

                        Chris Losinger wrote:

                        you can't use templates on structs - only on classes .

                        If you mean you can't use struct keyword inside of a template declaration, you are right. However, it is perfectly possible to make struct templates.

                        Programming Blog utf8-cpp

                        C Offline
                        C Offline
                        Chris Losinger
                        wrote on last edited by
                        #12

                        right. template < struct T > class nope {...}; = bad

                        image processing | blogging

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups