Hi I am just looking into using structs, in the tutorial videos I have seen on youtube so far they seem to be declared outside of the main function so I am guessing the use for this (and their purpose) is basically to be global, available for all functions.
I am currently creating 5,6 vectors of the same type inside my main function and passing them to 2 or 3 different functions after they have been processed by one they get processed to the other etc. I have been looking at ways to clean up the aesthetics of the code for my own sake. I was considering using typedef to avoid writing std::vector<std::string> myVec or std::vector<int> myVec which I think is a good solution.
Somebody on this forum suggested I looked into using a struct (so I did!) , it would be much easier to declare them once, not have to "pass" them in the function names to each function and just be able to type structname.firststruct etc. So I have a couple of questions regarding this.
Is it fine to make a struct if its all made of the same variable type? is the above example making good use of a struct and what other useful features or basic implementation examples of using structs are there that you could explain to me?
A struct is simply a grouping of data and methods (functions) to act on that data. In C++, generally people only stick data in structs. This is mostly a historical and stylistic thing. When people read 'struct' they're going to be expecting only data. Use a class if you want methods also.
Learning some OOP concepts would be very helpful for you here.
Hmm I just checked out a few tutorials around classes and it seems that most of them are based around the functions being similar in the class and being made public. Is this the best way to go? in my mind it would make more sense if the variables I have that are all of the same type being in the class, and each function just uses those public variables within the class?
Typically, you make variables private in a class, and have public methods that you allow to operate on them. This gives you control of what variables you want write access to, provides a layer of abstraction where you can stick sanity checks in, and provides looser coupling (should always strive for that in OOP).
Structs, since you usually are only sticking data in there it makes no sense to make that data private, so variables are public in struct (which is the default). Classes default to private access.