main difference between STRUCT AND CLASS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mack
    New Member
    • Feb 2007
    • 11

    main difference between STRUCT AND CLASS

    Hi,

    I want to ask what is basically main difference between struct and class??
    when we should use struct instead of class.??

    Mack.
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #2
    As a general rule (and I'm sure I'll be corrected, because I believe you can do other things), a structure is used to store items of data, a method/function is used to do things.....
    so a structure might be able to STORE x and x^2, but a method would take x and CALCULATE x^2

    Hope that makes some sense....

    Comment

    • chella
      New Member
      • Mar 2007
      • 51

      #3
      Originally posted by Mack
      Hi,

      I want to ask what is basically main difference between struct and class??
      when we should use struct instead of class.??

      Mack.

      Hi Mack,
      In Structure : The data members of a structure are not private. It can be accessed by any function in the program.

      In class : The data members of a class are secure since only the member functions of that class can access it. By usin class the data is more secure.

      Regards,
      Chella

      Comment

      • DeMan
        Top Contributor
        • Nov 2006
        • 1799

        #4
        And that will teach me for not reading the question properly (again).......

        Comment

        • Mack
          New Member
          • Feb 2007
          • 11

          #5
          Thanks friends

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by chella
            Hi Mack,
            In Structure : The data members of a structure are not private. It can be accessed by any function in the program.

            In class : The data members of a class are secure since only the member functions of that class can access it. By usin class the data is more secure.

            Regards,
            Chella
            Yes classes encapsulates data better an provides data security. They also allow for inheritance and polymorphism making it possible to write extensible and more efficient solutions to problems.

            Comment

            Working...