-2

I am confused in elaborated class name. I would be extremely grateful if described as example. Syntax: friend elaborated-class-name ;

  • Your question make no sense. Why not give us a small code example to work with? – Dennis Apr 05 '16 at 10:53
  • Adapted from here http://en.cppreference.com/w/cpp/language/friend Designates the class, struct, or union named by the elaborated-class-name 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.......I need only c++ example of it. – Aadarsha Subedi Apr 05 '16 at 10:57
  • 1
    You want us to write an example of how to use the `friend` keyword?? You need to do some research. This is not a tutorial site. – Dennis Apr 05 '16 at 10:59

3 Answers3

2

Elaborated class name just means class (or struct) keyword + actual name of the class.

Use it like this:

friend class Klass;
grisumbras
  • 850
  • 2
  • 6
  • 11
2

From n4140:

[class.friend]/3 :

A friend declaration that does not declare a function shall have one of the following forms:
friend elaborated-type-specifier ;
friend simple-type-specifier ;
friend typename-specifier ;

then you have an example:

class C;
typedef C Ct;
class X1 {
  friend C; // OK: class C is a friend
};
class X2 {
  friend Ct; // OK: class C is a friend
  friend D; // error: no type-name D in scope
  friend class D; // OK: elaborated-type-specifier declares new class
};

So: friend class D; is an example of elaborated-type-specifier. While friend D; is not and is called simple-type-specifier - which is new since C++11.

marcinj
  • 48,511
  • 9
  • 79
  • 100
0

Here is a demonstrative program

#include <iostream>

namespace usr
{
    int B = 20;

    class A
    {
    public:
        A( int x = 0 ) : x( x ) {}
        friend class B;  // using of elaborated type specifier
    private:
        int x;
    };

    class B
    {
    public:        
        std::ostream & out( const A &a, std::ostream &os = std::cout ) const
        {
            return os << a.x;
        }
    };
}

int main()
{
    class usr::B b;  // using of elaborated type specifier
    b.out( usr::A( 10 ) ) << ' ' << usr::B << std::endl;    
}    

Its output is

10 20
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335