Topic: A question about "Template name binding" in TC++PL
Author: sincereli@126.com (MichaelLi)
Date: Tue, 30 Mar 2004 16:10:26 +0000 (UTC) Raw View
I have a question about "Template Name Binding" in Section C.13.8.1 in
TC++PL written by Stroustrup.The example provided is as follow:
void g(double);
template class X : public T {
public:
void f() {g(2);} //call g(double);
};
void g(int);
class Z {};
void h(X<Z> x) { x.f(); } //call g(double). Really??
class Y {public: void g(int);};
//void h(X<Y> x) { x.f(); } //call g(double). Really??
I tried a test program in VC7 which said has the 100% conformance with
the C++Standard and get a totally different result.
#include<iostream>
void g(double) { std::cout<<"g(double) version"<<std::endl; }
template<class T>
class X : public T {
public:
void f() { g(2); }
};
void g(int) { std::cout<<"g(int) version"<<std::endl; }
class Z { };
class Y {
public:
void g(int) { std::cout<<"Y::g(int) version"<<std::endl; }
};
int main()
{
X<Z> z;
X<Y> y;
z.f(); //VC7 result: g(int) version Not call g(double)
y.f(); //VC7 result: Y::g(int) version Not call g(double)either
return 0;
}
Anyone can give me an advice?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: AlbertoBarbati@libero.it (Alberto Barbati)
Date: Tue, 30 Mar 2004 18:28:52 +0000 (UTC) Raw View
MichaelLi wrote:
> I tried a test program in VC7 which said has the 100% conformance with
> the C++Standard and get a totally different result.
According to the docs, conformance of VC7 was "significantly improved"
and that's undoubtedly true and a good thing. AFAICT, they are not
claiming 100% conformance. In fact VC7 does not yet support two-phase
binding of dependent names, as clearly stated in the docs:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/vclrf1462dependentnames.asp
(sorry for the long link... complain with Microsoft).
Alberto
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: Nicola.Musatti@ObjectWay.it (Nicola Musatti)
Date: Wed, 31 Mar 2004 15:13:54 +0000 (UTC) Raw View
AlbertoBarbati@libero.it (Alberto Barbati) wrote in message news:<kWhac.101735$FJ6.3741352@twister1.libero.it>...
> MichaelLi wrote:
> > I tried a test program in VC7 which said has the 100% conformance with
> > the C++Standard and get a totally different result.
>
> According to the docs, conformance of VC7 was "significantly improved"
> and that's undoubtedly true and a good thing. AFAICT, they are not
> claiming 100% conformance. In fact VC7 does not yet support two-phase
> binding of dependent names, as clearly stated in the docs: [...]
For what it's worth, they're in good company: of all the compilers
available to me (g++ 3.2, bcc32 5.6.4, como 4.3.3) only como gets it
right.
Cheers,
Nicola Musatti
P.S. Yes, I'm aware that both g++ 3.2 and bcc32 5.6.4 are not very up
to date.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]