By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,002 Members | 1,294 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,002 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 ******
"Patrick Kowalzick" <Pa***************@cern.ch> wrote in message
news:e0**************@TK2MSFTNGP10.phx.gbl...
Dear NG,

In thought the following program should compile without errors. Is there a
reason why it is not compiling ?

Thanks,
Patrick

#include <iostream>

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

template <typename T>
struct B_bar {
typedef T B_type;
};
int main()
{

B_bar< A_bar<double> >::B_type::A_type x;

B_bar< B_bar<double> >::B_type::B_type x; // this line causes Error in
MSVC 7.1
// test6.cpp(18) : error C2146: syntax error : missing ';' before
identifier 'x'
// test6.cpp(18) : warning C4551: function call missing argument list
}

Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Patrick Kowalzick wrote:
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
Nov 16 '05 #2

P: n/a
Thanks a lot.

Patrick

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
Patrick Kowalzick wrote:
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

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.