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;
};
Explanation
The first option will not work according to 7.1.5.3 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
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты