Select valid declarations for the template friends.
// 1
template <typename T>
class C {
    friend class T;

// 2
template <class T>
class C {
    friend T;

// 3
template <typename T>
class C {
    typedef T type;
    friend class type;
The first option will not work according to of Standard C ++: 3.4.4 describes how name lookup proceeds for the identifier in an elaborated-type-specifier. ... If the identifier resolves to a typedef-name or a template type-parameter, the elaborated-type-specifier is ill-formed. [Note: this implies that within a class template with a template type-parameter T, the declaration friend class T; is ill-formed. ]

The second has a slightly different problem:
An elaborated-type-specifier shall be used in a friend declaration for a class. The class-key of the elaborated-type-specifier is required.

The third option is just one of many variations with typedef, and is rather an attempt to confuse the compiler than a real solution.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Зареєструйся Зараз
або Підпишись на майбутні тести