473,324 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Dependent names lookup in VC2005 B2

Hello all,

I just checked that the following did compile with VC2005 b2, and I
think it shouldn't:

template <typename T> struct A
{
typedef int Foo;
};

template <typename T> class B : public A<T>
{
Foo i; //line 1
};
int main()
{
B<float> b;
}

I believe that Foo is a dependent-name in B context, and therefore line
1 should be "typename A<T>::Foo i;".

Comeau online and gcc seems to agree with my reasoning, but I am quite
unable to fully understand norm 14.6.2. Could anyone shed some light on
this? Is this code legal or not?

Arnaud
MVP - VC

Nov 17 '05 #1
2 1283
On 16 Jun 2005 01:09:52 -0700, ad******@club-internet.fr wrote:
Hello all,

I just checked that the following did compile with VC2005 b2, and I
think it shouldn't:

template <typename T> struct A
{
typedef int Foo;
};

template <typename T> class B : public A<T>
{
Foo i; //line 1
};
int main()
{
B<float> b;
}

I believe that Foo is a dependent-name in B context, and therefore line
1 should be "typename A<T>::Foo i;".

Comeau online and gcc seems to agree with my reasoning, but I am quite
unable to fully understand norm 14.6.2. Could anyone shed some light on
this? Is this code legal or not?


No, the code above isn't legal. If you remove A<T> as a base class and
refer to Foo with A<T>::Foo, I expect you'll get an error. If instead you
add "int Foo;" as a global in front of B's defintion, I expect you won't
get an error. The problem is that VC still doesn't correctly implement the
"two-phase" lookup rule and is still quite lax about looking into template
bases.

--
Doug Harrison
Microsoft MVP - Visual C++
Nov 17 '05 #2
Doug Harrison [MVP] <ds*@mvps.org> wrote:
On 16 Jun 2005 01:09:52 -0700, ad******@club-internet.fr wrote:
Hello all,

I just checked that the following did compile with VC2005 b2, and I
think it shouldn't:

template <typename T> struct A
{
typedef int Foo;
};

template <typename T> class B : public A<T>
{
Foo i; //line 1
};
int main()
{
B<float> b;
}

I believe that Foo is a dependent-name in B context, and therefore line
1 should be "typename A<T>::Foo i;".

Comeau online and gcc seems to agree with my reasoning, but I am quite
unable to fully understand norm 14.6.2. Could anyone shed some light on
this? Is this code legal or not?


No, the code above isn't legal. [...]


I think it is indeed illegal. Comeau agrees.
<lazy_mode>I'm sure CW agrees, too. At least
it keeps finding such errors that VC let's
me get away with.</lazy_mode>

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"Coming back to where you started is not the same as never leaving"
Terry Pratchett
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Carl | last post by:
I want to create a generic xslt that would take xml input like: ########################################################################## <?xml version="1.0" encoding="utf-8" ?>...
8
by: Falc2199 | last post by:
Hi, Does anyone know how to make this work? var sectionId = 5; repeat_section_sectionId(); function repeat_section_5(){ alert("firing"); }
13
by: Martin Vorbrodt | last post by:
simple program: #include <iostream> int main() { std::cout << "bleee" << endl; } both VC++.NET 2003 and GCC (3.3 i think) tell me that endl is an undefined identivier. is that correct, or...
2
by: shunah | last post by:
I'm building a form that lets users manage the app's lookup tables by adding and (maybe) removing values that show up in various combo boxes across the application. The original idea was to show...
2
by: indiana | last post by:
Thanks in advance. I have a vc6 dll that is currently called by a vc6 exe and want to call it from a vc2005 dll. The vc6 exe using the following header extern "C" __declspec(dllimport) int...
4
by: siddhu | last post by:
Dear experts, As far as I understood the ADL concept things should work in the following way. I have a global ostream operator defined as //ostreamtest.cpp #include<iostream> using...
0
by: =?GB2312?B?zPC5zw==?= | last post by:
Howdy, This problem have puzzled me for a long time. I usually use python2.5 in Windows, while VC2005 is installed. However python25.lib is compiled by VC2003. When I use disutil to build some C...
0
by: Christian Heimes | last post by:
甜瓜 schrieb: It's possible but ill-advised. The free mingw32 compiler can build Python extensions just fine. I'm using it all the time to build Python 2.5 extensions for Windows. In the...
2
by: puzzlecracker | last post by:
See it a lot but haven't learn the difference between this two in the context of template. Would someone explain it please? Thanks
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.