473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Public vs Friend

I have read and re-read VB.Net's help on scope of variables but darned if I can understand the difference between Friend and Public variables?
--
Dennis in Houston
Nov 20 '05 #1
4 18817
I have used it for controls and such.

Lets say you have a module wth code that needs to be public for other member
of your project, but you want it to be hidden from the end user. Declare it
Friend. If you want it to be accessed for everything then declare it
public.

I haven't found many times for the need, but does arise. For another
instance. I made a message box control that had 3 forms. I needed a class
to interact with the forms, but I didn't want a user to grab the forms, so I
made them friend classes.

Hope that help a little

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
I have read and re-read VB.Net's help on scope of variables but darned if I can understand the difference between Friend and Public variables? --
Dennis in Houston

Nov 20 '05 #2
I think I understand. Public class1 lets me access class1 in my assembly as well as other users who add my assembly to their projects. If I use Friend, then I can access class 1 in my assembly but others using the assembly in their projects cannot access class1. Thanks.
--
Dennis in Houston
"Lespaul36" wrote:
I have used it for controls and such.

Lets say you have a module wth code that needs to be public for other member
of your project, but you want it to be hidden from the end user. Declare it
Friend. If you want it to be accessed for everything then declare it
public.

I haven't found many times for the need, but does arise. For another
instance. I made a message box control that had 3 forms. I needed a class
to interact with the forms, but I didn't want a user to grab the forms, so I
made them friend classes.

Hope that help a little

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
I have read and re-read VB.Net's help on scope of variables but darned if

I can understand the difference between Friend and Public variables?
--
Dennis in Houston


Nov 20 '05 #3
friend vars are available to other members of the same package (i mean same
Namespace)
Public vars are available to other classes - even if not in the same
package - er Namespace

Java calls it package
VB calls it Namespace
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
I have read and re-read VB.Net's help on scope of variables but darned if I can understand the difference between Friend and Public variables? --
Dennis in Houston

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004
Nov 20 '05 #4
"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:ig**************@bignews1.bellsouth.net...
friend vars are available to other members of the same package
(i mean same Namespace)
Public vars are available to other classes - even if not in the same
package - er Namespace


Would that that were True.

In my experience, "Friend" only exposes stuff within the current
/Assembly/, and /not/, as I would /dearly/ like, the given Namespace!

Regards,
Phill W.
Nov 20 '05 #5

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

Similar topics

2
by: Christophe Barbe | last post by:
I posted a few days ago about the same problem but was not very clear. So here is my second take at it. Basically with GCC 3.3.2, I can't compile the example from the C++ FAQ Lite available...
12
by: Bryan Parkoff | last post by:
CMain Class is the base class that is initialized in main function. CA Class is the base class that is initialized in CMain::CMain(). CMain Class is always public while CA Class is always...
5
by: Srini nandiraju | last post by:
Hi folks, I am trying to implement a friend class and the following is what I did. Please scroll down. /***************** CODE **********************************/ class BKP { private: int...
4
by: ankit_jain_gzb | last post by:
Hi Iam not able to understand why the following code gives compile problem. Thanks Ankit Jain class B; class A{ public:
4
by: Alfonso Morra | last post by:
Is there a difference between these two: Decl 1 ============= class A {} ; class B { public: friend class A ; ......
1
by: Tony Johansson | last post by:
Hello experts! Assume I have this class definition of class ListElem. I'm a bit unsure how to interpret when you put friend declaration in public, protected and private section of a class...
6
by: Jim Langston | last post by:
Short version: class MyClass { friend class MyOtherClass::MySubClass; // Doesn't work }; class MyOtherClass { class MySubClass {
21
by: H9XLrv5oXVNvHiUI | last post by:
Hi, I have a question about injecting friend functions within template classes. My question is specific to gcc (version 3.4.5) used in combination with mingw because this code (or at least code...
8
boxfish
by: boxfish | last post by:
Hi everyone, I'm working on a 3d maze game, and I just messed up the classes so it won't compile, and I need help sorting it out. There's a class Maze, whose members are, among other things, a list...
3
JavierL
by: JavierL | last post by:
Im doing an excercise, where i need to use a friend class and a friend function from another class to access a private member of a third class. With the 'friend class' everything when OK, but i have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.