+ 5

Why would one prefer to use a struct over a class?

26th Oct 2016, 1:42 AM
Dan Rhamba
Dan Rhamba - avatar
2 odpowiedzi
+ 20
1)Is the main responsability of the type data storage? 2)Is its public interface defined entirely by properties that access or modify its data members? 3)Are you sure your type will never have subclasses? 4)Are you sure your type will never be treated polymorphically? If you answer 'yes' to all 4 questions: use a struct. Otherwise, use a class.
26th Oct 2016, 4:37 AM
Nelli
Nelli - avatar
+ 2
Structs are generally used for very simple "classes" that do not require private or protected data such as a point, node, ect for example.
5th Nov 2016, 7:24 AM
Paul Birkholtz
Paul Birkholtz - avatar