Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / July 2007

Tip: Looking for answers? Try searching our database.

Compiler Error With Protected Friend

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Neal - 27 Jul 2007 23:52 GMT
Hi all

Why do I get a compiler error with the following code.

Friend Class SomeClass
End Class

Public Class SomePublicClass

   Protected Friend Function AMethod As SomeClass
   End Function
End Class

Both the Protected Method and the SomeClass have the Same Scope (Friend) so
there should be no problem.

Regards
Neal
1388-2/HB - 28 Jul 2007 03:19 GMT
I think this is what the compiler is trying to avoid:

Public Class SomePublicClass
  Protected Friend Function AMethod As [Type]
  End Function
End Class

Public Class NotAFriend
 Inherits YourProject.SomePublicClass
 Sub New()
    Dim obj As Object = MyBase.AMethod 'ambiguous scope
 End Sub
End Class

> Hi all
>
[quoted text clipped - 14 lines]
> Regards
> Neal
Neal - 28 Jul 2007 13:08 GMT
Yes I agree, but surely it should not even be considered as being ambiguous
since the AMethod should never be available outside the project in the first
place since it's scope is of Friend. It appears Protected methods simply
ignore the Friend scope. If that's the case then the VB Editor really should
be removing the Friend Scope or showing an error in Error List saying
Protected Methods can only be of Public scope.

Regards
Neal

>I think this is what the compiler is trying to avoid:
>
[quoted text clipped - 28 lines]
>> Regards
>> Neal
Armin Zingler - 28 Jul 2007 13:47 GMT
> Yes I agree, but surely it should not even be considered as being
> ambiguous since the AMethod should never be available outside the
[quoted text clipped - 3 lines]
> showing an error in Error List saying Protected Methods can only be
> of Public scope.

"Protected Friend" does /not/ mean that the method is only visible to
inherited classes inside the same assembly. Instead it means that the method
is accessible from
a) all classes inside the same assembly
/as well as/
b) from inherited classes outside the assembly.

Due to b), the type "SomeClass" must be public, too.

In other words,
- "Protected" means that it is accessible from all inherited classes, even
outside the assembly.
- "Friend" means that it is accessible only inside the assembly but not only
limited to the inherited classes.

So, "Protected Friend" is not more limiting than Protected or Friend alone,
it is less limiting.

(see also F1)

Armin

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.