Click here to Skip to main content
15,889,739 members
Home / Discussions / C#
   

C#

 
GeneralRe: Inheritance Pin
MicroVirus27-Aug-11 8:46
MicroVirus27-Aug-11 8:46 
GeneralRe: Inheritance Pin
MicroVirus27-Aug-11 2:41
MicroVirus27-Aug-11 2:41 
GeneralRe: Inheritance Pin
lukeer27-Aug-11 3:33
lukeer27-Aug-11 3:33 
GeneralRe: Inheritance Pin
lukeer27-Aug-11 3:21
lukeer27-Aug-11 3:21 
GeneralRe: Inheritance Pin
lukeer27-Aug-11 3:19
lukeer27-Aug-11 3:19 
GeneralRe: Inheritance Pin
MicroVirus27-Aug-11 5:40
MicroVirus27-Aug-11 5:40 
AnswerRe: Inheritance [modified] Pin
Shameel26-Aug-11 4:40
professionalShameel26-Aug-11 4:40 
AnswerRe: Inheritance Pin
ClockEndGooner27-Aug-11 19:00
ClockEndGooner27-Aug-11 19:00 
Hi, Luker;

The related MSDN help topic for the similar compiler error I receive for the example at http://msdn.microsoft.com/en-us/library/s9zta243.aspxm, is:

"A derived class cannot access protected members of its base class through an instance of the base class. An instance of the base class declared in the derived class might, at run time, be an instance of another type that is derived from the same base but is not otherwise related to the derived class. Because protected members can be accessed only by derived types, any attempts to access protected members that might not be valid at run time are marked by the compiler as not valid."

If I'm following this explanation correctly, methods or member functions declared as protected can only be accessed by an immediate descendant of the base class. In the example above, since SecondDerived does not inherit its structure and behavior from FirstDerived, FirstDerived.DoSomething() cannot be called as the language is enforcing the scope and access of the protected method DoSomething(). Even if AbstracstBase.DoSomething() wasn't declared as abstract, the restricted access of the protected qualifier takes precedence.

Moreover, I don't think using the internal qualifier would help, as the compiler treats this as an error, in which the derived class, FirstDerived, was trying to change the access on a method that was inherited and declared as protected in the AbstractBase class. The internal keyword, in conjunction with a correctly defined assembly attribute, can only allow the runtime to access internal methods between friend assemblies. This approach for the friend qualifier seems specific to .NET, and unfortunately, is not the same as a friend function in C++.

Is it possible to provide an additional method in FirstDerived that would correctly expose and allow a call to FirstDerived.DoSomething() on behalf of the FirstDerived's consumer, or, could having the common polymorphic behavior of DoSomething() be expressed and implemented using an Interface instead?

I hope this was of help. If I missed something in your question, or incorrectly stated anything with regards to the use and application of the protected and internal keywords, please let me know.

Best Regards...

Bill
GeneralRe: Inheritance Pin
ClockEndGooner27-Aug-11 19:05
ClockEndGooner27-Aug-11 19:05 
QuestionADD "CorelDraw" file into C# App Pin
Mahtab77726-Aug-11 2:08
Mahtab77726-Aug-11 2:08 
AnswerRe: ADD "CorelDraw" file into C# App Pin
Wayne Gaylard26-Aug-11 2:36
professionalWayne Gaylard26-Aug-11 2:36 
GeneralRe: ADD "CorelDraw" file into C# App Pin
Mahtab77728-Aug-11 2:59
Mahtab77728-Aug-11 2:59 
GeneralRe: ADD "CorelDraw" file into C# App Pin
Mahtab77729-Aug-11 21:01
Mahtab77729-Aug-11 21:01 
QuestionMulti-Form Set Correct Output Pin
share_holder26-Aug-11 1:41
share_holder26-Aug-11 1:41 
QuestionRe: Multi-Form Set Correct Output Pin
Wayne Gaylard26-Aug-11 1:45
professionalWayne Gaylard26-Aug-11 1:45 
AnswerRe: Multi-Form Set Correct Output Pin
share_holder26-Aug-11 1:50
share_holder26-Aug-11 1:50 
QuestionRe: Multi-Form Set Correct Output Pin
Wayne Gaylard26-Aug-11 1:55
professionalWayne Gaylard26-Aug-11 1:55 
AnswerRe: Multi-Form Set Correct Output Pin
share_holder28-Aug-11 21:25
share_holder28-Aug-11 21:25 
QuestionRe: Multi-Form Set Correct Output Pin
V.26-Aug-11 1:48
professionalV.26-Aug-11 1:48 
AnswerRe: Multi-Form Set Correct Output Pin
share_holder26-Aug-11 1:53
share_holder26-Aug-11 1:53 
GeneralRe: Multi-Form Set Correct Output Pin
V.26-Aug-11 1:59
professionalV.26-Aug-11 1:59 
GeneralRe: Multi-Form Set Correct Output Pin
share_holder28-Aug-11 21:24
share_holder28-Aug-11 21:24 
AnswerRe: Multi-Form Set Correct Output Pin
BillWoodruff26-Aug-11 3:14
professionalBillWoodruff26-Aug-11 3:14 
GeneralRe: Multi-Form Set Correct Output Pin
share_holder28-Aug-11 21:22
share_holder28-Aug-11 21:22 
GeneralRe: Multi-Form Set Correct Output Pin
V.28-Aug-11 21:31
professionalV.28-Aug-11 21:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.