Adding a new design constraint to D
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Tue Jun 14 20:41:35 UTC 2022
On Tuesday, 14 June 2022 at 20:04:14 UTC, Dom Disc wrote:
> On Tuesday, 14 June 2022 at 17:24:31 UTC, Ola Fosheim Grøstad
> wrote:
>> On Tuesday, 14 June 2022 at 17:16:04 UTC, Dom Disc wrote:
>>> If it's a member, you can do nothing about it - not with
>>> module level nor with class level privacy. Also not in C++ or
>>> Java or any other language I know about.
>>
>> Not sure what you meant by this. You can make the member a
>> class that has its own privacy with a selective set of friends.
>
> What I mean is: You cannot prevent a member function from
> having access to the private variables of the class. Even if it
> should not touch them.
This seems to compile:
```C++
class A {
public:
inline void f();
inline void g();
private:
class X {
int value;
friend void A::f();
};
X x{};
};
void A::f(){
x.value++;
}
void A::g(){
//illegal: x.value++;
}
```
More information about the Digitalmars-d
mailing list