471,319 Members | 1,226 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

protected and private in C++ and C#

1st, simple question, is there a protected in C#?

I mean a comparable keyword like the C++ protected, which defines a member
as accessable for decendants, but not for the outside world.

Then, a more complicated question, is privat in C#, then comparable with
protected, or private in C++. Or to say it in other words, if I declare a
member private in C#, can I access it in a decendant class?
Jan 1 '06 #1
7 6278
My4thPersonality wrote:
1st, simple question, is there a protected in C#?

I mean a comparable keyword like the C++ protected, which defines a member
as accessable for decendants, but not for the outside world.

Then, a more complicated question, is privat in C#, then comparable with
protected, or private in C++. Or to say it in other words, if I declare a
member private in C#, can I access it in a decendant class?

The protected and private in C# have the same meaning as in C++. C#
extends access modifiers by adding internal and protected internal,
which are equal to public and protected with respect to the module they
appear in and private to the outer world.
Jan 1 '06 #2
My4thPersonality wrote:
1st, simple question, is there a protected in C#?

I mean a comparable keyword like the C++ protected, which defines a member
as accessable for decendants, but not for the outside world.

Then, a more complicated question, is privat in C#, then comparable with
protected, or private in C++. Or to say it in other words, if I declare a
member private in C#, can I access it in a decendant class?

The protected and private in C# have the same meaning as in C++. C#
extends access modifiers by adding internal and protected internal,
which are equal to public in the module in which they appear and private
or protected respectively to the outer world.
Jan 1 '06 #3
Stefan Simek <si**********@triaxis.nospam.sk> wrote:
Then, a more complicated question, is privat in C#, then comparable with
protected, or private in C++. Or to say it in other words, if I declare a
member private in C#, can I access it in a decendant class?
The protected and private in C# have the same meaning as in C++.


Is that strictly true? I *thought* that in C++, you couldn't access the
private members of one instance from another instance (whereas you can
in C#). This is only based on what others have said, however - I
haven't checked the spec.

There's also the concept of private inheritance in C++, but not in C#.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 1 '06 #4
Jon Skeet [C# MVP] wrote:
Stefan Simek <si**********@triaxis.nospam.sk> wrote:
Then, a more complicated question, is privat in C#, then comparable with
protected, or private in C++. Or to say it in other words, if I declare a
member private in C#, can I access it in a decendant class?

The protected and private in C# have the same meaning as in C++.

Is that strictly true? I *thought* that in C++, you couldn't access the
private members of one instance from another instance (whereas you can
in C#). This is only based on what others have said, however - I
haven't checked the spec.

Yes, you can access the private fields from another instance in C++.
There's also the concept of private inheritance in C++, but not in C#.

HTH,
Andy
--
To email me directly, please remove the *NO*SPAM* parts below:
*NO*SPAM*xmen40@*NO*SPAM*gmx.net
Jan 1 '06 #5
Andreas Mueller <me@privacy.net> wrote:
Is that strictly true? I *thought* that in C++, you couldn't access the
private members of one instance from another instance (whereas you can
in C#). This is only based on what others have said, however - I
haven't checked the spec.
Yes, you can access the private fields from another instance in C++.


My mistake. It must be another language I'm thinking of... I wonder
which?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 1 '06 #6

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Andreas Mueller <me@privacy.net> wrote:
> Is that strictly true? I *thought* that in C++, you couldn't access the
> private members of one instance from another instance (whereas you can
> in C#). This is only based on what others have said, however - I
> haven't checked the spec.

Yes, you can access the private fields from another instance in C++.


My mistake. It must be another language I'm thinking of... I wonder
which?


None I know of. In fact, "How come instance 1 can access private members of
instance 2?" seems to be a common newbie question about C#, C++, and Java
alike.
Jan 1 '06 #7
Actually, C++/CLI has "internal" and also has an equivalent to C#'s protected
internal: "public protected".
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter

"Stefan Simek" wrote:
My4thPersonality wrote:
1st, simple question, is there a protected in C#?

I mean a comparable keyword like the C++ protected, which defines a member
as accessable for decendants, but not for the outside world.

Then, a more complicated question, is privat in C#, then comparable with
protected, or private in C++. Or to say it in other words, if I declare a
member private in C#, can I access it in a decendant class?

The protected and private in C# have the same meaning as in C++. C#
extends access modifiers by adding internal and protected internal,
which are equal to public in the module in which they appear and private
or protected respectively to the outer world.

Jan 2 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Christian Meier | last post: by
3 posts views Thread by seesaw | last post: by
28 posts views Thread by Act | last post: by
13 posts views Thread by Adam H. Peterson | last post: by
16 posts views Thread by Fir5tSight | last post: by
2 posts views Thread by Morten71 | last post: by
8 posts views Thread by Mayur H Chauhan | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.