i have the following two classes :
class A{
enum ee{a = 1, b = 2 , c = 3};
};
class B{
/*
*/
};
Now i want to use enum ee in class B how i to friend enum ee in class A?\
you could restrict access more selectively using this approach:
class B;
class A {
class inner {
enum ee {a = 1, b = 2 , c = 3};
friend class B;
};
public:
typedef inner exposed;
};
class B {
void f() {
const A::exposed::ee e(A::exposed::a);
}
};
this introduces restrictions above the other options, for the times you want/need to be more specific wrt access.
specifically, A
does not need to be friends with B
using this approach, and the declarations in A::inner
are restricted as you have specified. A::inner
can then keep its declarations private, and allow access via friendship. clients could declare an inner
(accessed via A::exposed
), but it will be of no practical use to the client if the enum type and constants are private.
If you put the enum in the public section of A
, you can refer to it as A::ee
, and the values as A::a
, A::b
, and A::c.
class A
{
public:
enum ee {a = 1, b = 2 , c = 3};
};
class B
{
A::ee an_enum;
/* */
};
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