Feb 10, 2010 at 8:03am UTC
Hi, I am trying to pass some command line parameters to my class, I was wondering what is the proper way of doing so. Currently I try
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
class mmdm17tt
{
public :
mmdm17tt();
void allmax();
void amset();
enum command {AMSET, ALLMAX};
struct params
{
params():freq(-1.0),ampl(-1){};
double freq;
int ampl;
};
int docmd(const command& cmd, const params& prm);
};
class read_cmd
{
public :
read_cmd(int argc, char *argv[]);
mmdm17tt::params prm;
mmdm17tt::command cmd;
};
read_cmd::read_cmd(int argc, char *argv[])
{
string arg;
for (int i = 1; i < argc; i++)
{
arg = argv[i];
if (arg == "--amset" )
cmd = AMSET;
else if (arg == "--allmax" )
cmd = ALLMAX;
else if (arg == "-a" )
prm.ampl = atoi(argv[check_lim(++i)]);
else if (arg == "-f" )
prm.freq = atof(argv[check_lim(++i)]);
else
usage();
}
}
and compiler (gcc 4.3.4) complains about read_cmd constructor: `error: 'ALLMAX' was not declared in this scope'.
I tried to specify it as mmdm17tt::command::AMSET but then it says that mmdm17tt::command is not a class or namespace.
How shell I do it properly? Thank you.
Last edited on Feb 10, 2010 at 8:03am UTC
Feb 10, 2010 at 8:58am UTC
great, this works! many thanks. But is this the proper way to do that? I mean the style.
Feb 10, 2010 at 10:06am UTC
according to OOP conceptions yes, it's a good style(it's encapsulation).
But you have to understand that this enum is part of your class.
Last edited on Feb 10, 2010 at 10:06am UTC