+ 1

What is the difference between struct and class... ?

Related to c++...

15th Jan 2018, 4:23 AM
Maria
Maria - avatar
2 Antworten
+ 6
strict is a value type , like a string or int whereas class is object type . strict types can copy their value to another strict type . for example var age = 4; var newAge = age; now var age will copy the value of 4 and assign it to newAge . without any problems. any change in newAge will not effect the first age variable . but with class types (objects) you can't do the same thing . var object = new object(); var newObject = object; In this case the newObject variable is just a reference to the first object . so any change in the newObject will effect the original object . ################################### one more difference is that strict don't support inheritance because the value are placed on the stack . class on the other hand do support inheritance and objects are created on the heap. the stack is a small memory to store small data like variables and such the heap is designed to hold big data .
15th Jan 2018, 5:51 AM
jay
+ 4
Well, the major difference that exists between a struct and a class is the access modifier default of the two. The members of a class are private by default, while members of a struct are public by default. Classes in C++ are simply extensions of a structure used in the C language. It is a user defined data type.
15th Jan 2018, 4:51 AM
Dread
Dread - avatar