C++C++11C++14C++17Learn C++Syntax

What Is An Extended Friend Declaration in Modern C++?

What Is An Extended friend Declaration in Modern C++

In modern C++ the standards have a wonderfully named extended friend declaration feature to address the class declarations which is a template parameter as a friend. This extended friend declaration is available with the C++ compiler that has C++11 and above standards. In this post, we explain a friend and extended friend declaration in modern C++.

What is a friend declaration in modern C++?

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

C++11 extends the current language to support a wider range of friend declarations. Now, in modern C++has the extended friend declaration feature to address class declarations which is a template parameter as a friend. This extended friend declaration is available with a C++ compiler that has C++11 and above standards.

Syntaxes for the friend declaration (since C++11):

and

Is there a simple example of a friend declaration in modern C++??

Here is a simple friend declaration C++ example.

How do I make a function declaration with friend declaration in modern C++?

In C++, we can declare functions with friend. Here is the syntax:

and we can declare the F() function with friend as shown below.

How to create a function definition with friend declaration in modern C++?

In C++, we can define functions with friend. Here is the syntax how we can do,

and we can declare a reset() function with friend as below.

What is an elaborated class specifier with friend declaration in modern C++?

According to the C++ standard, an elaborated type specifier must be used in a friend declaration for a class. That means the class-key of the elaborated_ type_specifier is required. In C++, we can use elaborated class specifier with friend. Here is the syntax.

How to use a template with friend declaration in modern C++?

Here is an template example that uses friend.

How to use a namespace with friend declaration in a class in modern C++?

Here is a friend example that is used in a class of a namespace.

Is there a full example of an extended friend declaration in modern C++?

Here is a full example to extended friend declaration in modern C++.

For more information about the extended friend declarations feature, see Extended friend declarations Proposal document.

What Is An Extended friend Declaration in Modern C++ C++ Builder logo

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise version.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?