what is difference between structure and class?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Trupti rane
    New Member
    • Dec 2010
    • 1

    #1

    what is difference between structure and class?

    structure in c and class in c++
  • mysticwater
    New Member
    • Aug 2010
    • 14

    #2
    Structures can not have functions in them.
    Classes have the ADDED functionality of being able to have functions

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      There is only one difference between a struct and a class: The default access for struct members is public whereas the default access for class members is private.

      C++ comes from C and in C there is only one way to group data members together: a struct. Therefore, C++ has only structs.

      A class is a term used in object technology to represent a group of data members managed by operations.

      To make C++ look more object-like a "class" was added to the language. It is implemented as a struct with a private default access.

      That means C++ structs can have constructors, destructors, etc.

      Try it out. Write a class and get it working with a constructor, destructor and maybe another member function. Once it works, change the "class" keyword to "struct" and rebuild. You will see abolutely nothing happen. The code will work as before.

      Comment

      Working...