11 replies
what is the difference between structure and classes in c++?
#c++
  • Profile picture of the author Backlinks Weekend
    Structure offers you simple way to manage your data. For example, I can call an account is a simple structure with username and password.

    A class is an object, a complex and integrated type of structure where you can have member variables, functions, inheritance, etc. For example, I can have a dog class with function bark, etc.
    Signature
    GET RANK FAST OR MAINTAIN YOUR #1 SPOT - Daily Web 2.0 Submission. Insanely Powerful + Rave Reviews + PROOF!
    {{ DiscussionBoard.errors[2474359].message }}
    • Profile picture of the author ronperkins
      The structure default access type is public and should typically be used for grouping data.

      The class default access type is private and the default mode for inheritance is private. A class should be used for grouping data and methods that operate on that data.

      The convention is to use structures when the purpose is to group data, and use classes when we require data abstraction and, perhaps inheritance.
      {{ DiscussionBoard.errors[2476279].message }}
  • Profile picture of the author ksrao
    Hi,
    Structure is a collection of heterogeneous elements.
    For example if you have a
    int empno;
    Char empname[25];
    float salary;

    just i want to use as one structure
    let us c how can i do with the help of struct

    Struct emp
    {
    int empno;
    char empname[20];
    float salary;
    };
    struct emp e1,e2,e3;

    see now e1,e2 & e3 are struct type.
    now e1 will have all three Fields
    similarly e2 & e3 will have three fields.

    Class: Class is a collection of objects and methods which you can apply on it, rather
    you can say it is a collection of similar type of items.
    Regards
    Kolla Sanjeeva Rao
    {{ DiscussionBoard.errors[2481993].message }}
  • Profile picture of the author mike_hustler
    structure and classes both are you can say user defined data types. Both of them can have different predefine datatypes. the main difference is that classes have also member functions in it....
    {{ DiscussionBoard.errors[2485042].message }}
    • Profile picture of the author pollocktrance
      Accoring to Zeeshan "C++ structure and C++ class remain same after introducing virtual function or virtual inheritance ." then why we do introduce a keyword class.

      I mean if both are doing the same then whu unneceesary ly we have introduce a keyword class. There might be some reason behind the same
      {{ DiscussionBoard.errors[2497860].message }}
  • Profile picture of the author vonthomson
    In structures there is no security of the data but in case of a class there is a security because it binds both member data and member function on which the data acts.
    {{ DiscussionBoard.errors[2513730].message }}
  • Profile picture of the author jeniffer90
    Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public. Class: Class is a successor of Structure. By default all the members inside the class are private. ..
    {{ DiscussionBoard.errors[2519372].message }}
  • Profile picture of the author harris2107
    thanks all for your help..
    {{ DiscussionBoard.errors[2544238].message }}
    • Profile picture of the author Barbaradavid
      The members of a structure have public visibility by default, and the members of a class have private visibility by default, so because of the private visibility, the class encourages the use of encapsulation, classes support polymorphism, whereas structures does not support polymorphism, structure does not provide data hiding, well class provides data hiding.
      {{ DiscussionBoard.errors[2563446].message }}
  • Profile picture of the author zeeshi570
    OO you have asked a very basic question.

    you can get many answers on internet. Do RND for this
    {{ DiscussionBoard.errors[2565031].message }}
  • Profile picture of the author harris2107
    thanks alot.
    {{ DiscussionBoard.errors[2828680].message }}

Trending Topics