Topic: Access modifiers in C++0x
Author: Anders Dalvander <google@dalvander.com>
Date: Thu, 13 Dec 2007 11:53:26 CST Raw View
Hi,
Is there a suggestion for C++0x to allow direct access modifiers to
members as a compliment to the current scoped and default access
modifier rules?
For example:
class foo
{
public int a(); // public due to direct access modifier.
protected int b(); // protected due to direct access modifier.
int c(); // private due to default access modifier.
public:
int d(); // public due to scoped access modifier.
protected int e(); // protected due to direct access modifier.
int f(); // public due to scoped access modifier.
}
Regards,
Anders Dalvander
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: v.Abazarov@comAcast.net ("Victor Bazarov")
Date: Thu, 13 Dec 2007 18:49:03 GMT Raw View
Anders Dalvander wrote:
> Is there a suggestion for C++0x to allow direct access modifiers to
> members as a compliment to the current scoped and default access
> modifier rules?
I hope not!
>
> For example:
>
> class foo
> {
> public int a(); // public due to direct access modifier.
> protected int b(); // protected due to direct access modifier.
> int c(); // private due to default access modifier.
>
> public:
> int d(); // public due to scoped access modifier.
> protected int e(); // protected due to direct access modifier.
> int f(); // public due to scoped access modifier.
> }
Such code is really difficult to read and comprehend. Intersperse
it with 'static' and 'virtual' and you quickly get *a mess*.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Douglas Gregor <doug.gregor@gmail.com>
Date: Thu, 13 Dec 2007 14:24:33 CST Raw View
On Dec 13, 12:53 pm, Anders Dalvander <goo...@dalvander.com> wrote:
> Is there a suggestion for C++0x to allow direct access modifiers to
> members as a compliment to the current scoped and default access
> modifier rules?
No, there are no proposals to introduce this extension into C++0x.
- Doug
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: michaelsafyan@aim.com (Michael Aaron Safyan)
Date: Fri, 14 Dec 2007 15:39:53 GMT Raw View
Anders Dalvander wrote:
> Hi,
>
> Is there a suggestion for C++0x to allow direct access modifiers to
> members as a compliment to the current scoped and default access
> modifier rules?
>
> For example:
>
> class foo
> {
> public int a(); // public due to direct access modifier.
> protected int b(); // protected due to direct access modifier.
> int c(); // private due to default access modifier.
>
> public:
> int d(); // public due to scoped access modifier.
> protected int e(); // protected due to direct access modifier.
> int f(); // public due to scoped access modifier.
> }
>
> Regards,
> Anders Dalvander
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
>
Such an extension would be unnecessary. Just add a colon and you get a
similar effect:
class foo
{
public: int a();
protected: int b();
private: int c();
public: int d();
protected: int e();
public: int f();
};
IMHO, I see no reason why would want to do what you propose; having to
write "public" a million times is the one thing I dislike most about Java.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Anders Dalvander <google@dalvander.com>
Date: Fri, 14 Dec 2007 12:44:46 CST Raw View
On Dec 14, 4:39 pm, michaelsaf...@aim.com (Michael Aaron Safyan)
wrote:
> Such an extension would be unnecessary. Just add a colon and you get a
> similar effect:
Similar, but not same effect. Using a scoped modifier (as traditional C
++, using colon) will set the access modifier for all class members
from that point on, a direct modifier (as Java, C# and other
languages, without using colon) will only set it for a specific
member.
> IMHO, I see no reason why would want to do what you propose; having to
> write "public" a million times is the one thing I dislike most about Java.
What I propose is that both syntaxes shall work, you don't have to use
a direct modifier if you don't want to, you could use the scoped
modifier if you want to.
Direct modifiers would make refactoring easier, for instance: Moving a
class member from one place in a class to another may change it's
access modifier as it may be moved to another access modifier scope.
Or if changing the access modifier for a single class member without
moving it, you'll need to write two access modifier scopes: One for
setting the new access modifier for the class member, and one for
resetting the access modifier back to what it was, so that all later
class members will remain in the same old scope.
Regards,
Anders
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]