C
Cliff Martin
I want to define several groups of related magic numbers. I am writing
a program to parse someone else's formatted data, and they have
several fields that could be set to a number of different values.
Rather than hardcode a number I want to use a text to make it clear
what I am comparing to.
examples:
FieldA
1 foo
2 bar
3 baz
FieldB
1 foo
2 bar
3 baz
I would like to make comparisons like:
if (b_val == FieldB.foo)
// do something
rather than
if (b_val == 1)
// do something
What kind of data structure would allow me do this? I think that
struct is what I am looking for, but I could also make a class for
each field type.
What is the best way to approach this?
Where would I declare this, in my header file?
Could I also define it there?
Cliff
a program to parse someone else's formatted data, and they have
several fields that could be set to a number of different values.
Rather than hardcode a number I want to use a text to make it clear
what I am comparing to.
examples:
FieldA
1 foo
2 bar
3 baz
FieldB
1 foo
2 bar
3 baz
I would like to make comparisons like:
if (b_val == FieldB.foo)
// do something
rather than
if (b_val == 1)
// do something
What kind of data structure would allow me do this? I think that
struct is what I am looking for, but I could also make a class for
each field type.
What is the best way to approach this?
Where would I declare this, in my header file?
Could I also define it there?
Cliff