473,786 Members | 2,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

declaring friend

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 definition. If you insted have
declared a primitive type or a class type then I would understand it
completely.
I assume that having a friend declaration in the private section make no
sense.
I assume that you always put friend declaration in the public section.

Example 1
class ListElem
{
public:
friend class List
.. . .
};

Example 2
class ListElem
{
protected:
friend class List
.. . .
};

Exampl 3
class ListElem
{
private:
friend class List
.. . .
};

Many thanks

//Tony
Aug 15 '05 #1
1 2157

"Tony Johansson" <jo************ *****@telia.com > wrote in message
news:4e******** *************@n ewsc.telia.net. ..
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 definition. If you insted
have declared a primitive type or a class type then I would understand it
completely.
No difference where you declare a friend in the class.
I assume that having a friend declaration in the private section make no
sense.
I assume that you always put friend declaration in the public section.


By declaring something as a friend you are granting permission for that
something to access the private part of the class. A sole friend statement
encapsulates nothing and therefore is not bound by access permissions.
Logically a friend (class or function) is an augmentation of a class's
public interface, and it seems natural to put that in public. However,
unlike member functions, you don't need to know the class to use its friend,
so it is okay to put the friend statement in private.

Ben

Aug 15 '05 #2

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

Similar topics

5
1455
by: James Aguilar | last post by:
Hello, all. I saw this in the provided code of a lab that I have due in a couple of weeks in my algorithms class. It compiled fine in g++ but did not compile with the VC++ compiler. It does not recognize the angle brackets that follow "<<" in the operator friend declaration. --- CODE --- template <class T> class PriorityQueue {
14
1888
by: lutorm | last post by:
Hi, I'm having a problem with a return statement being parsed to return a function (I think). Check here: template <typename T> class A {}; template <typename T> class maker_of_A { public: A<T>& make_A() {return A<T>();}; };
2
1873
by: Terry Holland | last post by:
I have a an assembly with the following code Module modEnums Public Enum enuFixType ftyButtSide 'jamb full height, header inside jambs ftyButtTop 'header full width, jambs butt up to header ftyMorticeSide 'tenons at each end of header ftyMorticeTop 'tenons at end of jambs End Enum
1
1681
by: John Dann | last post by:
Is there a way of declaring an array of a structure where the structure has a constructor? So if I had a structure say Friend MyStructure prop1 as integer prop2 as string sub New (p1 as integer, p2 as string) me.prop1=p1 me.prop2=p2 End Sub
3
2268
by: jbeteta | last post by:
Hello, I have a problem declaring variables. I need to create an object oRpte as ReportClass on WebForm1.aspx and be able to use its value on WebForm2.aspx. For declaring the property oRpte() on WebForm1.aspx, I use "Public Property" and I declare variable _oRpte as Friend Shared. That's my problem. If I don't declare _oRpte as Friend Shared, I can't use WebForm1.oRpte() on other webpage. If I declare _oRpte as Friend Shared, I can use...
11
4760
by: Jim Michaels | last post by:
friend fraction& operator+=(const fraction& rhs); fraction.h(64) Error: error: 'fraction& operator+=(const fraction&)' must take exactly two arguments I practically pulled this out of a C++ book (except for the "friend"). can someone explain why GCC is giving me problems here? for a += or similar operator, what does a proper declaration look like and what are its arguments for?
1
2052
by: curious2007 | last post by:
Hello everybody, When I try to declare nontemplate friend functions I get the following warning: friend decleration......declares a non-template function (if this is not what you intended, make sure the function tempate has already been declared and add<> after the function name here)-Wno-non-template-friend disables this warning. Since declaring a non-template friend function is what i have intended, I would like to disable this...
2
2595
by: Hicham Mouline | last post by:
Hello, I am attempting to change a existing large code base and I have this situation: A.hpp class A { .... friend void B::member_function1() const; ...
4
1798
by: Fred Blair | last post by:
Where is the correct place to declare an array so that it will be available anywhere in the project. I have been playing with one form that has two buttons and one listbox. I want each button to add a name from an array to the list box. Unless I declare the array inside each button_click event, it says the array has not been declared. Help please,
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9496
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6745
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4066
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 we have to send another system
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.