+ 5
Why would one prefer to use a struct over a class?
2 Réponses
+ 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.
+ 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.