-
Classes and Structures.
I read that classes and structures are completely the same, after learning that you should use structures for data, and classes for both data and functions. The only difference from what i read between classes and structures is that structures are public by default and classes are private by default. If this is the only difference does it matter which one you use?
-
>If this is the only difference does it matter which one you use?
Aside from default permissions, the only difference is in your mind. Use whatever makes more sense. I usually use classes for full data types and structures for little things, like linked list nodes.
-
Ok, thanks. What are full data types?
-
>What are full data types?
I see I used potentially confusing terminology. :) A class would be used for all but the simplest objects. So while a struct would be used for a linked list node, a class would be used for the linked list.
-
Also with structures, I do not think that they come with a default constructor, so there is no way to initalise your variables declared within your structure when you declare an instance of the structure. Therefore, classes are safer to use as you can always make sure the variables are initalised before you start doing any work on the data.
-
>I do not think that they come with a default constructor
Aside from the default permissions, structures are exactly the same as classes. That includes the default constructor.
-
Ok, I stand corrected. I wonder where I read that anyways? Ah well.