VC++ 7.1 friend template problem

J

Jaroslav Gresula

Consider the following code:

template<class T>
struct Singleton
{
static T& Instance()
{
static T instance;
return instance;

}
};

template<class T>
struct A : public Singleton<A<T> >
{
// causes error C2245
friend A& Singleton<A<T> >::Instance();
};

A<int>& i = A<int>::Instance();

Comeau online is OK with it, VC++ is not.
It is a bug or am I missing something?

Cheers,
Jarda
 
C

Carl Daniel [VC++ MVP]

Jaroslav said:
Consider the following code:

template<class T>
struct Singleton
{
static T& Instance()
{
static T instance;
return instance;

}
};

template<class T>
struct A : public Singleton<A<T> >
{
// causes error C2245
friend A& Singleton<A<T> >::Instance();
};

A<int>& i = A<int>::Instance();

Comeau online is OK with it, VC++ is not.
It is a bug or am I missing something?

Looks like a bug to me.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top