Friend templates & Spezialisierung



  • Hi. Folgende Situation:

    template<typename t = void>
    class foo
    {
    };
    
    template<typename t,
             typename u = foo<> >
    class bar
    {
    };
    
    template<typename t,
             typename u>
    class bar<t, foo<u> >
    {
        template<typename v>
        friend class bar<v, foo<u> >;
    };
    

    Resultiert mit Visual C++ 9.0.21022.8 in:

    error C2976: 'bar<t,foo<u>>' : too few template arguments
    

    Wie krieg ich das hin?
    Danke schon mal für jegliche Hilfe 😉



  • Okay. Sieht nicht so gut aus:

    Compiler Error C3772
    ...It is invalid to declare a friend of a class template specialization...
    
    To correct this error
    Do not declare a friend of a class template specialization. 
    
    If appropriate for your application, declare a friend of the class template, or declare a friend of a particular partial or explicit specialization.
    

    Können die anderen Compiler das?



  • Der friend ist doch sowieso völlig unnütz, da jede bar-Methode auf alle Member einer beliebigen bar-Instanz zugreifen kann (also auch private).

    Oder willst du irgendwie bar und foo gegenseitig befreunden?


  • Mod

    Eine friend-Templatedeklaration darf keine partielle Spezialisierung deklarieren (14.5.3/9). Der Compiler hat recht, aber die Fehlermeldung ist irreführend.


Anmelden zum Antworten