Problem with typedef in template class - (again, sorry)

P

Patrick Kowalzick

Hello NG,

sorry to bother again, but I am a lit surprised that I got no answer on my
post (attached below).
So I refined the code a little bit :).

If there is a typedefed class X inside a class Y which has the same typedef
name and used in the form "Instance_Y::type::type" MSVC7.1 fails to compile.
See example below.

It looks like a kind of name-hiding, which I do not understand in this
context. In my opinion it should not be here (ok, i am not very good in
interpreting the standard).

If I posted in the wrong newsgroup, please tell me where I should post.

Regards,
Patrick


// ***** CODE START ******

#include <iostream>

template <typename T>
struct A_bar {
typedef T A_type;
typedef T A_value;
};

template <typename T>
struct B_bar {
typedef T B_type;
typedef T B_value;
};

template <typename T>
struct B_bar2 {
typedef T B_type;
typedef T B_value;
};


int main()
{

B_bar< A_bar<double> >::B_type::A_value x1;
B_bar< A_bar<double> >::B_type::A_type x2;

B_bar< B_bar<double> >::B_type::B_value y1;
// B_bar< B_bar<double> >::B_type::B_type y2; // this line causes errors
in MSVC 7.1
// test6.cpp(29) : error C2146: syntax error : missing ';' before
identifier 'y2'
// test6.cpp(29) : warning C4551: function call missing argument list
// test6.cpp(29) : error C2065: 'y2' : undeclared identifier
// but there is a small work-around
typedef B_bar< B_bar<double> >::B_type dummy_type_B;
dummy_type_B::B_type y3;

B_bar< B_bar2<double> >::B_type::B_value z1;
// B_bar< B_bar2<double> >::B_type::B_type z2; // same errors & warnings
// test6.cpp(34) : error C2146: syntax error : missing ';' before
identifier 'z2'
// test6.cpp(34) : warning C4551: function call missing argument list
// test6.cpp(34) : error C2065: 'z2' : undeclared identifier
// but there is the same workaround
typedef B_bar< B_bar2<double> >::B_type dummy_type_B2;
dummy_type_B2::B_type z3;

}


// ***** CODE END ******
 
C

Carl Daniel [VC++ MVP]

Patrick said:
Hello NG,

sorry to bother again, but I am a lit surprised that I got no answer
on my post (attached below).
So I refined the code a little bit :).

If there is a typedefed class X inside a class Y which has the same
typedef name and used in the form "Instance_Y::type::type" MSVC7.1
fails to compile. See example below.

It looks like a kind of name-hiding, which I do not understand in this
context. In my opinion it should not be here (ok, i am not very good
in interpreting the standard).

If I posted in the wrong newsgroup, please tell me where I should
post.

This ng is appropriate.

I was able to reproduce the problem that you describe and I agree that it
looks like a compiler bug, which is also not fixed in the Whidbey alpha.
I'll submit the bug to the VC team so it will be fixed in a future release.

You've already found the workaround of using the intermediate typedef.

-cd
 
P

Patrick Kowalzick

Thanks a lot.

Patrick

Carl Daniel said:
This ng is appropriate.

I was able to reproduce the problem that you describe and I agree that it
looks like a compiler bug, which is also not fixed in the Whidbey alpha.
I'll submit the bug to the VC team so it will be fixed in a future release.

You've already found the workaround of using the intermediate typedef.

-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