I need to parse a large amount of command line arguments. I was thinking the way I could do this from main was to have a class that dealt with this, but then I would need to pass-back, or pass-to another class all the various chunks of info.
The easiest way I thought of doing this would be a struct, but then I haven't used them before additionally all the examples I've seen do not have structs from within classes.
I'm wondering if it's possible to do this, and if so do I need the same struct in the class and main (so a copy in each) or do I reference the struct in the class by class.struct.data.
Or should I just chuck in a pile of set/get methods to deal with the data and throw out the notion of using a struct?
Really so it can't be done? That's silly... you can have nested structs, you can create structs with objects/classes as it's fields(although it's an expensive copy doing that).
I figured you could do it the other way around as well.
It can be done, I suppose, but it seems a bit redundant to me... You already have the data inside the class you use to parse the command line, why would you want to copy it to another construct?
Yeah I suppose, I thought it would be easier than 8+ lines of getThis() getThat(); in my main.
I figured out how to do it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class Class {
public:
// constructors and members
struct ClassStruct {
};
ClassStruct method(int x, std::string y, char c);
};
Class::ClassStruct Class::method(int x, std::string y, char c)
{
// definition
}