How to solve the problem of the accessibility of members ?

  • Thread starter Thread starter stephan
  • Start date Start date
S

stephan

How to solve the problem of the accessibility of members among files( .h or
..cpp )
in __gc classes?



Ex :

// AA.h file
public __gc class AA : UserControl
{
/* snip */
};

// BB.h file
public __gc class BB : UserControl
{
access-specifier int _b ;
/* snip */
};


AA can access _b of BB and all the classes can't except AA.
I can do it using "friend" if not __gc class.
How to do it on __gc class?

BTW, what is the reason that MS has removed "friend" in __gc class?

Thank.
 
stephan said:
How to solve the problem of the accessibility of members among files(
.h or .cpp )
in __gc classes?



Ex :

// AA.h file
public __gc class AA : UserControl
{
/* snip */
};

// BB.h file
public __gc class BB : UserControl
{
access-specifier int _b ;
/* snip */
};


AA can access _b of BB and all the classes can't except AA.
I can do it using "friend" if not __gc class.
How to do it on __gc class?

BTW, what is the reason that MS has removed "friend" in __gc class?

There's no support for friend access in the CLR. You'll have to change your
design to not rely on friends if you're targeting the CLR.

-cd
 
"Jochen Kalmbach" wrote :

declare it as "private public:" or "protected public:"

If there are AA and BB on the *same* file, these access-specifiers
work. If not, they don't work. Both AA and BB were inherited from
class "UserControl". therefore, there can't be AA and BB on the same file.

Thanks.
 
"Carl Daniel [VC++ MVP]" wrote :

There's no support for friend access in the CLR. You'll have to change your
design to not rely on friends if you're targeting the CLR.

Forgive me. what is the reason that MS don't support friend access in the
CLR?
 
stephan said:
"Carl Daniel [VC++ MVP]" wrote :

There's no support for friend access in the CLR. You'll have to
change your design to not rely on friends if you're targeting the
CLR.

Forgive me. what is the reason that MS don't support friend access
in the CLR?

friend access is generally considered dangerous, even in C++. I suppose
they decided there wasn't a sufficiently compelling reason to allow it.

-cd
 
You can get somewhat of an equivalent by making the members public and using
a declarative code access security check for the identity of the immediate
caller.

Note that in practice in standard C++ you can get around any accessibility
of members by casting or any variant of techniques whereas on the CLR
platform there is a hard enforcement of the accessibility.

Ronald Laeremans
Visual C++ team

Carl Daniel said:
stephan said:
"Carl Daniel [VC++ MVP]" wrote :

There's no support for friend access in the CLR. You'll have to
change your design to not rely on friends if you're targeting the
CLR.

Forgive me. what is the reason that MS don't support friend access
in the CLR?

friend access is generally considered dangerous, even in C++. I suppose
they decided there wasn't a sufficiently compelling reason to allow it.

-cd
 
Back
Top