Sdílet prostřednictvím


Chyba kompilátoru C3772

"name" : Neplatná deklarace šablony přítele

Poznámky

Je neplatné deklarovat přítele specializace šablony třídy. Nelze deklarovat explicitní nebo částečnou specializaci šablony třídy a ve stejném příkazu deklarovat přítele této specializace. Zástupný symbol názvu identifikuje neplatnou deklaraci.

Oprava této chyby

  • Deklarujte přítele specializace šablony třídy.

  • Pokud je to vhodné pro vaši aplikaci, deklarujte přítele šablony třídy nebo deklarujte přítele konkrétní částečné nebo explicitní specializace.

Příklad

Následující příklad kódu selže, protože deklaruje přítele částečné specializace šablony třídy.

// c3772.cpp
// compile with: /c

// A class template.
    template<class T> class A {};

// A partial specialization of the class template.
    template<class T> class A<T*> {};

// An explicit specialization.
    template<> class A<char>;

class X {
// Invalid declaration of a friend of a partial specialization.
    template<class T> friend class A<T*>; // C3772

// Instead, if it is appropriate for your application, declare a
// friend of the class template. Consequently, all specializations
// of the class template are friends:
//    template<class T> friend class A;
// Or declare a friend of a particular partial specialization:
//    friend class A<int*>;
// Or declare a friend of a particular explicit specialization:
//    friend class A<char>;
};

Viz také

Šablony
Specializace šablon