Question about Pointer to Member Typedefs inside templates

W

wbasheer

Hi,

Can anyone please tell me why this code is giving me a C2327 error? I
am using Visual C++ 2008.

template<class T, int T::*IntMemberOfT>
class Foo
{
};

class Bar
{
public:
int memberOfBar;
typedef Foo<Bar, &Bar::memberOfBar> TypeDefedFooBar;
};

The errors I see are:
error C2327: 'Bar::memberOfBar' : is not a type name, static, or
enumerator => Why am I seeing this one?
error C2065: 'memberOfBar' : undeclared identifier => This one will
probably go away once C2327 is gone.

If I move the type definition outside of Bar's scope it compiles
successfully.

Thanks
Waseem
 
V

Victor Bazarov

Can anyone please tell me why this code is giving me a C2327 error? I
am using Visual C++ 2008.

template<class T, int T::*IntMemberOfT>
class Foo
{
};

class Bar
{
public:
int memberOfBar;
typedef Foo<Bar, &Bar::memberOfBar> TypeDefedFooBar;
};

The errors I see are:
error C2327: 'Bar::memberOfBar' : is not a type name, static, or
enumerator => Why am I seeing this one?
error C2065: 'memberOfBar' : undeclared identifier => This one will
probably go away once C2327 is gone.

If I move the type definition outside of Bar's scope it compiles
successfully.

There seems to be no specific difference except that if you move
the typedef outside, 'Bar' is now a complete type. It can just
be a bug in the compiler. You should probably ask in the Visual
C++ newsgroup as well.

Try compiling your test program with online Comeau trial. If it
compiles it successfully, mention that in the VC++ newsgroup.

V
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top