Re: Why won't this compile
- From: "Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@xxxxxxxxxxxxxxx>
- Date: Mon, 12 Dec 2005 10:47:27 -0800
"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
.
- Follow-Ups:
- Re: Why won't this compile
- From: Tom Widmer [VC++ MVP]
- Re: Why won't this compile
- Prev by Date: Re: Why won't this compile
- Next by Date: Re: how to transfer a DWORD from a function?
- Previous by thread: Re: Why won't this compile
- Next by thread: Re: Why won't this compile
- Index(es):
Relevant Pages
|