473,725 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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::ty pe::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_va lue x1;
B_bar< A_bar<double> >::B_type::A_ty pe x2;

B_bar< B_bar<double> >::B_type::B_va lue y1;
// B_bar< B_bar<double> >::B_type::B_ty pe 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_va lue z1;
// B_bar< B_bar2<double> >::B_type::B_ty pe 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******** ******@TK2MSFTN GP10.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_ty pe x;

B_bar< B_bar<double> >::B_type::B_ty pe 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
2 2205
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::ty pe::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
Thanks a lot.

Patrick

"Carl Daniel [VC++ MVP]" <cp************ *************** **@mvps.org.nos pam>
wrote in message news:%2******** ********@TK2MSF TNGP10.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::ty pe::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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4254
by: Me | last post by:
I am not understanding an aspect of how to implement a class template in a ..cpp file. What I do know is that there are at least two problems with my understanding of how to accomplish the definition of a template outside the class. One problem is how to refer to a typedef that is a member of the classe's public interface in the .cpp file. The second problem is that if I modify my code to use the template variables and not my typedefs,...
11
2505
by: Alexander Stippler | last post by:
Hi, I have a little problem to design some template classes in a realizable way. I have some Container classes and some Proxy classes (proxies for elements). Looks like this: // P is the Proxy class. template <typename T, typename P> class Container {
3
1657
by: Boris | last post by:
Hello, I have written a program that compiles just fine with GCC 3.3. With GCC 3.4.1 it results in this error: g++ -O0 -g3 -Wall -c -oTestp.o ../Testp.c .../Testp.c: In function `int main()': .../Testp.c:26: error: no match for 'operator<=' in 't <= 2.0e+0' Please help me, I have no idea where the problem is.
3
2958
by: Generic Usenet Account | last post by:
This is a two-part question. (1) I have implemented a "Datastructure Registry" template class. I am getting no compiler warnings with older compilers, but newer compilers are generating the following error messages: warning: implicit typename is deprecated, please see the documentation for details Can someone kindly suggest how to get rid of these warnings? The source code follows.
6
1578
by: Hendrik Schober | last post by:
Hi, I have a problem with extending some existing code. In a simplified form, the problem looks like this: I have four types, A, B, C, and D. Each A refers to zero, one, or more B's and each B can be child to zero, one, or more A's. I just call that "A is a parent of B", and "B is a child of A". The same goes for B and C and for C and D. So A is only a parent, B and C are both parents and children, and D is only a child.
7
2333
by: T.A. | last post by:
Class hierarchy below demonstrates my problem: #include <vector> #include <boost/smart_ptr.hpp> class Fruit { public: virtual ~Fruit() = 0; };
9
2662
by: Jerome Durand | last post by:
Hello, I'm trying to write something along the following lines but I cannot get this to compile. template <typename derivedstruct Base { typedef typename derived::valueType valueType; virtual valueType Value() = 0; };
4
1814
by: Hora | last post by:
Hi Guys I'm reading Andrew Koenig and Barbara E. Moo 's book, Accelerated C++. It's the best works for newbie I ever read. The way the authors introduce the language is very interesting. In chaper 11th, they teach us how to implement our own vector. I rewrite the program, but I found a very curious question. When you place the Vec<T>::Vec( ) constructor in the .CPP file, the compliler complain that undefined reference to...
6
2613
by: abir | last post by:
i have a template as shown template<typename Sclass Indexer{}; i want to have a specialization for std::vector both const & non const version. template<typename T,typename Aclass Indexer<std::vector<T,A {} matches only with nonconst version. anyway to match it for both? and get if it is const or nonconst? Actually i want 2 specialization, one for std::vector<T,Aconst & non const other for std::deque<T,Aconst & non const.
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8096
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4517
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.