Friend: noun one attached to another by affection or esteem. CyberFriends is a popular, fun, safe, and anonymous online friendship portal where thousands of people from over 200 countries meet and chat every day. Our site was originally founded in 1995 when the Internet was just getting started, long before there was Netflix, Youtube, or Google. Since then, Cyber Friends has helped thousands of people. RentAFriend.com has Friends from around the world available for hire. Covid-19 Update July 2021: States and countries are starting to lift their restrictions. Please use social distancing if not vaccinated when meeting in person. Our Friends are also offering 'Virtual Friend Services' such as Facetime, Zoom, Texting, Phone Friends and more. Friend to Friend America recruits and matches volunteers to visit (one-to-one) with elderly and disabled persons who live in nursing, assisted living, retirement, and adult family homes for the purpose of forming friendships. The volunteer friends make a commitment to visit at least twice a month at their convenience, for a minimum of one year. 3) Designates the class, struct, or union named by the elaborated-class-specifier (see elaborated type specifier) as a friend of this class.This means that the friend's member declarations and definitions can access private and protected members of this class and also that the friend can inherit from private and protected members of this class.

< cpp‎ language
C++
Language
Standard Library Headers
Freestanding and hosted implementations
Named requirements
Language support library
Concepts library(C++20)
Diagnostics library
Utilities library
Strings library
Containers library
Iterators library
Ranges library(C++20)
Algorithms library
Numerics library
Localizations library
Input/output library
Filesystem library(C++17)
Regular expressions library(C++11)
Atomic operations library(C++11)
Thread support library(C++11)
Technical Specifications
Classes
General
Overview
class/struct types
union types
Injected-class-name
Members
Data members
Static members
The this pointer
Nested classes
Member templates
Bit fields
using-declarations
Member functions
Member access specifiers
Constructors and member initializer lists
Default member initializer(C++11)
friend specifier
explicit specifier
Converting constructor
Special member functions
Default constructor
Copy constructor
Move constructor(C++11)
Copy assignment operator
Move assignment operator(C++11)
Destructor
Inheritance
Base and derived classes
Empty base optimization
Virtual member functions
Pure virtual functions and abstract classes
override(C++11)
final(C++11)

The friend declaration appears in a class body and grants a function or another class access to private and protected members of the class where the friend declaration appears.

[edit]Syntax

friendfunction-declaration (1)
friendfunction-definition (2)
friendelaborated-class-specifier; (3)
friendsimple-type-specifier;

friendtypename-specifier;

(4)(since C++11)

[edit]Description

1) Designates a function or several functions as friends of this class
2) (only allowed in non-local class definitions) Defines a non-member function, and makes it a friend of this class at the same time. Such non-member function is always inline.
3) Designates the class, struct, or union named by the elaborated-class-specifier (see elaborated type specifier) as a friend of this class. This means that the friend's member declarations and definitions can access private and protected members of this class and also that the friend can inherit from private and protected members of this class.The name of the class that is used in this friend declaration does not need to be previously declared.
4) Designates the type named by the simple-type-specifier or typename-specifier as a friend of this class if that type is a (possibly cv-qualified) class, struct, or union; otherwise the friend declaration is ignored. This declaration will not forward declare a new type.

[edit]Notes

Friendship is not transitive (a friend of your friend is not your friend).

Friend

Friendship is not inherited (your friend's children are not your friends).

Storage class specifiers are not allowed in friend function declarations. A function that is defined in the friend declaration has external linkage, a function that was previously defined, keeps the linkage it was defined with.

Access specifiers have no effect on the meaning of friend declarations (they can appear in private: or in public: sections, with no difference).

A friend class declaration cannot define a new class (friendclass X {}; is an error).

When a local class declares an unqualified function or class as a friend, only functions and classes in the innermost non-class scope are looked up, not the global functions:

A name first declared in a friend declaration within a class or class template X becomes a member of the innermost enclosing namespace of X, but is not visible for lookup (except argument-dependent lookup that considers X) unless a matching declaration at the namespace scope is provided - see namespaces for details.

[edit]Template friends

Both function template and class template declarations may appear with the friend specifier in any non-local class or class template (although only function templates may be defined within the class or class template that is granting friendship). In this case, every specialization of the template becomes a friend, whether it is implicitly instantiated, partially specialized, or explicitly specialized.

Friend declarations cannot refer to partial specializations, but can refer to full specializations:

When a friend declaration refers to a full specialization of a function template, the keyword inline and default arguments cannot be used.

A template friend declaration can name a member of a class template A, which can be either a member function or a member type (the type must use elaborated-type-specifier). Such declaration is only well-formed if the last component in its nested-name-specifier (the name to the left of the last ::) is a simple-template-id (template name followed by argument list in angle brackets) that names the class template. The template parameters of such template friend declaration must be deducible from the simple-template-id.

In this case, the member of any specialization of A becomes a friend. This does not involve instantiating the primary template A: the only requirements are that the deduction of the template parameters of A from that specialization succeeds, and that substitution of the deduced template arguments into the friend declaration produces a declaration that would be a valid redeclaration of the member of the specialization:

Friendship Site

Default template arguments are only allowed on template friend declarations if the declaration is a definition and no other declarations of this function template appear in this translation unit.

(since C++11)

[edit]Template friend operators

A common use case for template friends is declaration of a non-member operator overload that acts on a class template, e.g. operator<<(std::ostream&, const Foo<T>&) for some user-defined Foo<T>

Such operator can be defined in the class body, which has the effect of generating a separate non-template operator<< for each T and makes that non-template operator<< a friend of its Foo<T>

Output:

or the function template has to be declared as a template before the class body, in which case the friend declaration within Foo<T> can refer to the full specialization of operator<< for its T:

[edit]Example

stream insertion and extraction operators are often declared as non-member friends

Output:

[edit]Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
CWG 45 C++98 members of a class nested in a friend class of T have no
special access to T
a nested class has the same access as
the enclosing class
CWG 500 C++98 friend class of T cannot inherit from private or protected
members of T, but its nested class can
both can inherit from such members

[edit]References

  • C++11 standard (ISO/IEC 14882:2011):
  • 11.3 Friends [class.friend]
  • 14.5.4 Friends [temp.friend]
  • C++98 standard (ISO/IEC 14882:1998):
  • 11.3 Friends [class.friend]
  • 14.5.3 Friends [temp.friend]

[edit]See also

Class declaration
Access specifiers
Retrieved from 'https://en.cppreference.com/mwiki/index.php?title=cpp/language/friend&oldid=125167'

Are you thinking of starting a Friends group, reorganizing or revitalizing the one you have, or a seasoned group looking for some fresh ideas? Look no further! United for Libraries offers a wealth of ideas and resources for Friends groups of all types, sizes, and level of activity. Explore the links in the menu to the left under 'Friends Groups' and throughout the rest of the United for Libraries website.

United for Libraries Resources

We've compiled a handy Excel file of the top resources available FREE and for members only. Please note this is a working compilation and resources may be added at any time. Also, it's not possible to list all of the wonderful links and resources we have on our site, so if you are looking for something and can't find it on this list, email Beth (bnawalinski@ala.org) or Jillian (jwentworth@ala.org) and we'll let you know if we have the resource and if so, where to find it.

  • United for Libraries Resources (Excel, 12.94 kb) Updated 5/22/17

Power Guide for Successful Library Advocacy

United for Libraries, along with the Neal-Schuman Foundation, believe strongly that advocacy can and does work. We’ve seen evidence of it from coast to coast in all types of libraries at the local and the state levels. Developing an advocacy campaign, as you will soon see, is not rocket science but it does take dedication, hard work, a core group of people who are passionate about the cause and the support of many, many people in your community. This guide will take the mystery out of advocacy, provide you with an organized step-by-step approach, and allow you to develop a set of strategies that will motivate your community to pressure funders to support the library or in the case of a referendum or a bond issue – to vote “yes.”

Free Toolkits

Libraries Need Friends: Starting a Friends Group or Revitalizing the One You Have (PDF, 100 kb) by Sally Gardner Reed, former Executive Director, United for Libraries, is a free toolkit geared mostly toward public library Friends groups, but with good tips on membership and outreach for Friends groups of any type.

Academic Library Friends: A Toolkit for Getting Started – You Can Do This! (PDF, 165 kb) by Charles D. Hanson, Director of Kettering Library Services, Kettering University, is a free toolkit from United for Libraries geared toward starting a Friends group at a community college or university.

Friend Of Friend Site Login

Friends Groups: Critical Support for School Libraries (PDF, 66 kb), by Sally Gardner Reed, former Executive Director, United for Libraries, is a free toolkit geared toward school librarians looking to create a Friends group of parents, faculty, and community members and/or a Student Friends Group.

Baby Boomer Volunteers for Libraries and Friends

The baby boomers are retiring! And...they are volunteering in large numbers in communities across the country. If libraries and Friends groups aren’t successful in recruiting this special group, some other community agency will be. This three-part series of webcasts is designed to inform library Friends, Trustees, and staff about this new generation of baby boomer volunteers — how they are different from volunteers in the past, what they want from service opportunities, and how libraries and Friends can attract them. Courses include:

  • Meet Today's New Volunteers
  • Friends and Baby Boomers - Getting New Active Members for Your Group
  • Library Volunteers - Bringing in Skilled and Committed Baby Boomers

Learn more, register, or access courses now! NOTE: Online registration is only available for the single-seat (member or non-member) option. To register for the multi-seat, single library site option, please see the registration form (PDF, 267 kb).

Friend Your Library Promotional Materials

'Friend Your Library' downloads and buttons (in packs of 6 or 18) are available for purchase from the ALA Store. ALA members automatically receive a 10% discount. United for Libraries group members should log into the Friends & Foundations Zone or Trustee Zone (based on group member type) to learn how to save 10% on the purchase of these materials. NOTE: Member discounts do not apply to special offers or sets. Discounts are not combined.

Available in both Zones is a downloadable 'Friend Your Library' graphic you can use on your Friends group or library website.

Public Service Annoucements for Friends Group Featuring Paula Poundstone

'There I was in another unbalanced relationship,' begins Emmy Award-winning comedian Paula Poundstone in a new public service announcement, which can be see below and online at YouTube along with a 15 second version. Permission is granted for Friends of the Library groups to imbed these videos on their websites to promote the Friends to their local communities.