What is the difference between class and structure?
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.
There should be no confusions. The only difference between a structure and a class is that all members in a class are private by default whereas they are public in a structure.
Above answer was rated as good by the following members: OSaienni, vjy_2107
There should be no confusions. The only difference between a structure and a class is that all members in a class are private by default whereas they are public in a structure.
Try inheritance polymorphism overloading encapsulation etc. all these are possible.........
1. struct data is public by default.. but its private in a class 2. class is successor of struct in heirarchy.. 3. struct is ovrloaded.. in C++ its not same with class..
Originally posted by rajalekshmy+r 1)can we provide datahiding with structures? if yes how? 2)can structures suport run time polymorphism? If yes how? By writing code? Again whatever you can do in a class you can do in a struct. Why not write code and see for yourself?
RE: What is the difference between class and structure?
A structure and a Class in C++ are same in every aspect expect in structure by default data members and member functions are public and private in case of class.