protected and private in C++ and C#

  • Thread starter Thread starter My4thPersonality
  • Start date Start date
M

My4thPersonality

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?
 
My4thPersonality said:
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.
 
My4thPersonality said:
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.
 
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 said:
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
 
Jon Skeet said:
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.
 
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
 
Back
Top