How can I use the members of enum state_t in the method bar::install without redefining it in the public class section of foo? Class member _state must stay protected.
Is it a good idea just to use another enum with similiar names for the members?
class foo
{
protected:
int _bla
volatile enum state_t { _REC, _LIN, _OFF } _state;
public
volatile enum { REC, LIN, OFF };
state_t get_state(void) { return _state };
};
Within a method of another class:
void bar::install(foo *ptr)
{
switch(ptr->get_state()) {
case foo::REC: break;
case foo::LIN: break;
case foo::OFF: break;
}
}
No, when you duplicate your enums you suffer extra effort when you modify them, you will also run into errors/warnings related to theirs types. I would make
state_tpublic and keep_stateprotected by separating their definition, like this: