0

I'm trying to write a class that will read and organize the command line arguments of a program.
Like, it will read -a as a 'switch', and --abcd as a 'switch' and you can define different switches as having parameters, so -a bc de fg will have bc and de as its parameters (that MUST go after -a if -a is defined as having two parameters) and fg would (if -a was only defined as having two parameters) be a standalone "statement"... anyway,
is it possible to overload the [] brackets in a class?
Say if -a had two switches, and there was an object aswitch for that switch...

cout<< aswitch; would output true if -a was set, false if otherwise,
cout<< aswitch[0]; would output the first parameter, and
cout<< aswitch[1]; would output the second.
right now I just have bool aswitch::isSet(); and char* aswitch::params(int);

Also, I don't know if i have the right understanding of "friend" functions...

class className{
public:
    friend int funcName();
protected:
    static char* varName;
};

int funcName(){
className varName = "newValue";
return 0;
}

making a "friend" function gives just a normal function outside a class access to that class's protected members right? Did I use it correctly in this example?

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by winrawr
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.