+ 2

I can not understand difference between Class and Struct.

10th Oct 2016, 12:07 AM
amir_afiy
amir_afiy - avatar
2 Réponses
+ 3
the major difference is in the instantiation.....a struct can not be initialized using the new keyword bt a class can. e.g you have a class named 'man' and also a struct name 'dog'. to initialize we do this; man x = new man (); then, dog y = "bark"; this means that struct doesn't have a default constructor just like classes (unless otherwise created). Also struct is a value type while class is a reference type. This means that struct variables directly hold the values themself but class variables are more like reference to the value, they hold the address to the value
13th Oct 2016, 10:27 PM
Maduekwe Ebuka Collins
Maduekwe Ebuka Collins - avatar
0
Structs are used for simple "classes" that do not require private/hidden data, subclasses or polymorphism. struct ex: node, point, firstLastName class ex: Bankaccount, enemy, world
5th Nov 2016, 7:38 AM
Paul Birkholtz
Paul Birkholtz - avatar