473,508 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compiler Error With Protected Friend

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
Jul 27 '07 #1
3 1725
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

"Neal" <N@NoSpam.comwrote in message
news:uR**************@TK2MSFTNGP04.phx.gbl...
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


Jul 28 '07 #2
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

"1388-2/HB" <1@1.netwrote in message
news:RE*************@nlpi070.nbdc.sbc.com...
>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

"Neal" <N@NoSpam.comwrote in message
news:uR**************@TK2MSFTNGP04.phx.gbl...
>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


Jul 28 '07 #3
"Neal" <N@NoSpam.comschrieb
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.
"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

Jul 28 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1237
by: William Payne | last post by:
Hi, I recently upgraded my compiler to a version that's a lot more touchy about code not conforming to the ISO standard. Right now I am in the process of compiling my old programs with the new...
12
2651
by: Andrew Schepler | last post by:
When compiled with Visual C++ .NET 2003 (only), the program below aborts as though no matching catch clause is present. If the copy constructor of A is made public, it successfully catches the...
0
1053
by: Dilip | last post by:
Vaclav I have taken the liberty to cross-post this microsoft.public.dotnet.languages.vc which has more visibility from MSFT VC++ team. thanks --Dilip Actual post by Vaclav Haisman...
3
2421
by: Adriano | last post by:
Hello, when I try to print something, either DataGrid or from Crystal Report viever the folowing error message appears and cancels printing: Object reference not set to an instance of an...
1
8807
by: Mikey G | last post by:
Hi, I created a simple VB.NET 2003 application through Visual Studio that connects to a MySQL database and loads a table into a Dataset, and then displays that table information in a DataGrid on a...
2
1460
by: Edd | last post by:
Hello all, Please consider: class Base { public: int pub; protected: int prot; private: int priv; };
2
1868
by: dc15 | last post by:
I am trying to write an application, taking input from various text boxes and appending it to a text file.... it was working, then I had to create various sub procedures to reflect limits set in...
6
4128
by: Rick | last post by:
Hi, Can anyone explain to me why the below fails to compile - seeing otherA->f(); as a call to a inaccessible function, while otherB->f(); is ok? It seems you can happily access protected...
12
1726
by: Wilson | last post by:
Hi, while writing a simplified version of a program i created the following class, however when i went to compile and run the program there was an error saying "multiple types in one...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3192
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.