Re: Why won't this compile

Tech-Archive recommends: Fix windows errors by optimizing your registry



"Larry" <Larry@xxxxxxxxxxxxx> wrote in message
news:F0A979C1-E43D-4632-8BB7-B651D1D32BD6@xxxxxxxxxxxxxxxx
> Hi there,
>
> Can someone explain why the following code won't compile in both VC7 and
> VC8
> (yields an error that the default constructor I'm invoking is private).
> I've
> made the calling function a friend however so it shouldn't happen as far
> as I
> know. Thanks.

You haven't made the function a friend. Rather, you've made a non-template
function name Func a friend.

You want this:


template <class T>
class CTest
{
CTest()
{
}

template <class U>
friend void Func(T);
};

template <class T>
void Func(T)
{
CTest<T> Var;
}

int main()
{
Func(3);
return 0;
}

-cd


.



Relevant Pages

  • Re: Circular Class Template Friendship
    ... > My issue is the syntax of declaring a friend class within ... > which the string is a fixed width that is specialized. ... it is still possible to have Name_Id_Table template ... the friend class declaration. ...
    (comp.lang.cpp)
  • Re: Class templates and friend function templates
    ... > It never occurred to me that the friend declaration could be an overload. ... > template ... I suspect the online version uses an EDG option to "instantiate ...
    (microsoft.public.vc.language)
  • Re: Template friendship to nested template class
    ... friend struct INNER; ... Probably you are missing an EXTRA template to declare ... I think it's because the name referred to in a 'friend' declaration is looked up to exist at the namespace scope. ...
    (microsoft.public.vc.language)
  • Re: Template friendship to nested template class
    ... template ... friend struct INNER; ... Both VC and gcc are happy with this code, but the intel compiler is ...
    (microsoft.public.vc.language)
  • Re: Class templates and friend function templates
    ... friend void process; ... each specialization of the `task' class template has all specializations of the function template `func' as friends. ... It only has one parameter that is distinct, thus implying a kind of partial specialisation of the friend declaration once C is instantiated for a particular type. ...
    (microsoft.public.vc.language)