I have a class that looks like this:
namespace R
{
class R_Class
{
enum R_Enum
{
R_val1,
R_val2,
R_val3
}
private:
// some private stuff
public:
// some public stuff
}
}
I'm performing unit testing using an automated test tool. The compiler claims that my test harness cannot access the type R::R_Class::R_Enum.
I have no trouble accessing the values within a similar class that is defined as such:
namespace S
{
class S_Class
{
public:
enum S_Enum
{
S_val1,
S_val2,
S_val3
}
}
private:
// some private stuff
public:
// some public stuff
}
Do enums in C++ need to be given explicit visibility directives? If not given any, do they default to private? protected?
enum
s obey visibility in classes just like attributes, methods, nested classes or anything else. You need to make it public
for outside visibility.
This is so that classes can have private enums used by its own private methods without exposing the enum
values to the outside world.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With