Re: union protected access
From: Derrick Coetzee (dcnews_at_moonflare.com)
Date: 09/02/04
- Next message: Howard: "Re: debug assertion failed str!=NULL fprintf.c"
- Previous message: Mike Wahler: "Re: binary number"
- In reply to: Paul: "Re: union protected access"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 02 Sep 2004 12:59:19 -0400
Paul wrote:
> Derrick Coetzee <dcnews@moonflare.com> wrote in message news:<ch5rr6$qn4$1@news-int2.gatech.edu>...
>
>>Even just having public and private in unions is rather silly, since the
>>presence of even one public field exposes all the others to mutation,
>>breaking encapsulation.
>
> [ . . . ] we can still access private, does this mean public, private,
> protected are useless in C++.
The point of protected and private are not to make it impossible for
someone to access the data, but to make it difficult enough that they
aren't likely to do it accidentally. In a union, it's easy to access the
data as long as a public member is visible, so easy that it could be
done accidentally and cause errors. This is what I mean by breaking
encapsulation in a C++ context.
-- Derrick Coetzee I grant this newsgroup posting into the public domain. I disclaim all express or implied warranty and all liability. I am not a professional.
- Next message: Howard: "Re: debug assertion failed str!=NULL fprintf.c"
- Previous message: Mike Wahler: "Re: binary number"
- In reply to: Paul: "Re: union protected access"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|