English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

8 answers

in a class u can write a function
in structure u cant

in calss u can define public n private functions n variables
in structure u cant

u can uze inheritance in class
in structure u cant

2006-07-09 21:02:08 · answer #1 · answered by Rockford 2 · 0 0

Dear the main diff. between class and structure is that the data type for the class is reference where for the structure it's value type what that's mean? it's mean that the structure instance is located in the memory in the stack direct while the object(instance) of the class is located in the heap and there is a pointer on it from the stack. how this will affect? the structure can't have inheritance cos. inheritance needs reference data type, the structure can't have constructor or destructor while also they needs a reference type to deal with, dealing with structure will be better in performance cos. it's directly located in the stack without any references delays like structure. but for the reference types (class) it takes more time to deal with it but the class is better where it have constructor and destructor and inheritance which is very useful features so what should you do? you have to use the structure unless you will need one of these features inheritance-constructor-destructor. so what about the functions most of you said that the structure didn't have functions in it actually this is not correct while it depends on the lang. which you use while in lang. like visual basic.net you can make function in the structure

2006-07-09 22:01:36 · answer #2 · answered by amr_osama 3 · 0 0

I really don't understand on what basis people are giving answers to this question. You should have specified language first before asking any such question. Since I programme in C++ so I would want to answer this question on the basis of my knowledge about C++. First of all I want to make clear that struct inside C++ do support defining functions inside them. Classes and structs (and even union) can have constructors and destructors. They have property of data hiding too i.e. you can control visibility of variable or objects inside struct using private and protected keywords and here comes the first difference between struct and class.By default Data members of structs are public, while private inside class.Structures inside C++ also support inheritance. So there is only one difference in my knowledge. I've tried to expalain my answer as much as I can. Hope this helps you.

2006-07-10 00:17:25 · answer #3 · answered by latola son of rock n rolla 2 · 0 0

Structures, base for C is just a collection of several grouped data items of different data types under one super identifier.

Whereas, Classes the base of OOPs & the increment of C++ is the collection of several data items of different data types along with different Functions related to them all grouped under one OBJECT.

2006-07-09 21:10:00 · answer #4 · answered by abhishekkr 2 · 0 0

Stuctures hold only data, whereas a class holds data and methods. If you want a more detailed explanation it is really worth your while performing a web search for tutorials relevant to the language you are concerned with.

2006-07-09 21:02:55 · answer #5 · answered by Anonymous · 0 0

Structure is subset of class

2006-07-09 21:11:00 · answer #6 · answered by Anonymous · 0 0

structure holds different variables of diff data types
class is wrapping or encapsulating the functions

2006-07-09 21:05:07 · answer #7 · answered by Enigma 2 · 0 0

Structures=>"only collection of datatypes"

struct
{
datatype1 name1; /*int,float,double....*/
datatype2 name2;
.................;
}



###########################
returntype class
{
methods(); (functions)
variables;
...............;
}

2006-07-09 23:13:49 · answer #8 · answered by india_kakinada 2 · 0 0

fedest.com, questions and answers