| | #1 |
| Warrior Member Join Date: 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
what is the difference between structure and classes in c++?
|
| | |
| |
| | #2 |
| HyperActive Warrior War Room Member Join Date: 2010 Location: Crowded City
Posts: 321
Thanks: 23
Thanked 19 Times in 15 Posts
|
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. |
| GET RANK FAST OR MAINTAIN YOUR #1 SPOT - Daily Web 2.0 Submission. Insanely Powerful + Rave Reviews + PROOF!
| |
| |
| | #3 |
| Senior Warrior Member War Room Member Join Date: 2010 Location: UK
Posts: 83
Thanks: 2
Thanked 10 Times in 10 Posts
|
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. |
| | |
| |
| | #4 |
| Warrior Member Join Date: 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
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 |
| |
| | #5 |
| Mike Hustler Join Date: 2010 Location: United States
Posts: 7
Thanks: 0
Thanked 1 Time in 1 Post
|
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....
|
| | |
| |
| | #6 |
| Warrior Member Join Date: 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
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 |
| | |
| |
| | #7 |
| Warrior Member Join Date: 2010 Location: Los Angeles, CA, 90060
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
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.
|
| | |
| |
| | #8 |
| Warrior Member Join Date: 2010
Posts: 26
Thanks: 5
Thanked 5 Times in 5 Posts
|
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. .. |
| |
| | #9 |
| Warrior Member Join Date: 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
thanks all for your help.. |
| | |
| |
| | #10 |
| Warrior Member Join Date: 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
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.
|
| | |
| |
| | #11 |
| Active Warrior Join Date: 2010
Posts: 88
Thanks: 1
Thanked 3 Times in 3 Posts
|
OO you have asked a very basic question. you can get many answers on internet. Do RND for this |
| |
| | #12 |
| Warrior Member Join Date: 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
thanks alot.
|
| | |
| |
|
| Bookmarks |
| Tags |
| c++ |
| |