c++ - [bug] two-phase name lookup
- Christof Meerwald (35/35) Aug 06 2005 The following test-case should print "OK" (see 14.6.2 (3)), but I get "F...
- Walter (1/1) Aug 20 2005 This is taken care of in the new beta.
- jay.a.carlson gmail.com (16/51) Aug 24 2005 I am sure Christof is much more knowledgeable than myself but I have to ...
- Walter (10/20) Aug 25 2005 ask:
- Travis (34/34) Apr 28 2008 try this---
The following test-case should print "OK" (see 14.6.2 (3)), but I get "FAIL" with DMC 8.44.6n: #include <stdio.h> void f() { printf("OK\n"); } template<class T> struct A { void f() { printf("FAIL\n"); } }; template<class T> struct B : A<T> { void g() { f(); } }; int main() { B<int> b; b.g(); return 0; } bye, Christof -- http://cmeerw.org mailto:cmeerw at web.de xmpp:cmeerw at cmeerw.org ...and what have you contributed to the Net?
Aug 06 2005
I am sure Christof is much more knowledgeable than myself but I have to ask: why not replace this with this template<class T> template<class T> struct B : A<T> struct B : A<T> { { void g() { f(); } void g() { ::f(); } // only modified line }; }; A<T> has a function f() and global namespace has a function f(). Using ::f() explicity calls the global function f() therefore removing the ambiguity. Is the original code really a compiler failure? (OK I didn't test it on DM because I am at work. But it did work an another compiler.) /r Jay Carlson In article <newscache$4w3tki$4t2$1 msgid.cmeerw.org>, Christof Meerwald says...The following test-case should print "OK" (see 14.6.2 (3)), but I get "FAIL" with DMC 8.44.6n: #include <stdio.h> void f() { printf("OK\n"); } template<class T> struct A { void f() { printf("FAIL\n"); } }; template<class T> struct B : A<T> { void g() { f(); } }; int main() { B<int> b; b.g(); return 0; } bye, Christof -- http://cmeerw.org mailto:cmeerw at web.de xmpp:cmeerw at cmeerw.org ...and what have you contributed to the Net?jay.a.carlson gmail.com
Aug 24 2005
<jay.a.carlson gmail.com> wrote in message news:dejfag$213l$1 digitaldaemon.com...I am sure Christof is much more knowledgeable than myself but I have toask:why not replace this with this template<class T> template<class T> struct B : A<T> struct B : A<T> { { void g() { f(); } void g() { ::f(); } // only modified line }; }; A<T> has a function f() and global namespace has a function f(). Using ::f() explicity calls the global function f() therefore removing the ambiguity. Is the original code really a compiler failure?Christof writes code to test compiler features and standards conformance, so the bug reports he posts are usually not the result of some bug he's trying to work around. He's got a nice web page up comparing standards conformance of various C++ compilers: http:///cmeerw.org. I owe Christof a big debt of gratitude as he's the one who figured out everything that was going wrong with DMC++'s early template implementation and distilled them all down to short & sweet bug reports.
Aug 25 2005
try this--- #include <stdio.h> #include <iostream> #include <conio.h> using namespace std; int main(); void f() { printf("OK\n"); } template<class T> struct A { void f() { printf("FAIL\n"); } }; template<class T> struct B : A<T> { void g() { f(); } }; int main() { B<int> b; b.g(); getchar(); return 0; }
Apr 28 2008