Hi, I'm just beginning to learn about structures, pointers, and references. I'm trying to practice what I've learned. I understand the idea of these new concepts, but when I'm having trouble knowing when and how to use them. In order to practice I've started a simple contact list program. I am hoping that you guys could help point out some instances where the use of structures, pointers(non-existent), and references are used correctly or incorrectly, and where they could be used correctly. This would really help me understand what I'm doing before my program turns into a big ball of confusion.
I didn't know I could use those with structures. I thought that was only for use of classes. Would I just place the functions within the structure as if it were an entirely public class, then call on them using methods?
in c you would be correct. structs are similar to classes in c++. methods are are functions either defined or declared in a class. you can have them public or private
Would it be beneficial to to define and declare the functions inside of the struct? If so, how would it be beneficial? Also, are constructors used the same way they would be in a class?
to your second question: yes
to the first: it depends. a method is usually a function that pertains to the struct or class. like if you made a function that printed everything in a vector, regardless of type, you wouldnt put that in your class, but if you made one that just did a vector of your structs, you would want to put that in it
Okay, I am understanding this as how to organize the functions. If the function has only to do with the struct, then to make that function a method of the struct would enhance readability.
How about references and pointers: Am I referencing correctly in this code? Are there any places that a pointer might better the efficiency?