From -4959712950869504571 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,58b61be817def08c X-Google-Attributes: gidf78e5,public From: bill@gibbons.org (Bill Gibbons) Subject: Re: this-> required? Date: 1998/04/29 Message-ID: #1/1 X-Deja-AN: 349491155 Approved: stephen.clamage@sun.com (comp.std.c++) References: <354657D6.C45E924F@xilinx.com> Originator: clamage@taumet X-NNTP-Posting-Host: bgibbons.vip.best.com X-UID: 0000000001 X-Status: $$$T X-Trace: 893823102 13287 (none) 206.86.0.12 Organization: -none- Newsgroups: comp.std.c++ In article <354657D6.C45E924F@xilinx.com>, Lou Sanchez-chopitea wrote: > Is the following snippet of code correct? > > template class Base > { > public: > int fBase ( void) { return 1;} > }; > > template class Derived : public Base > { > public: > int f1 ( void) { return fBase();} > int f2 ( void) { return this->fBase();} > }; > > In particular, is the this-> in f1 required? Thanks. In article <3546960D.9B44837C@acm.org>, Pete Becker wrote: > Lou Sanchez-chopitea wrote: > > > > > > In particular, is the this-> in f1 required? > > No. Yes, it is. The contents of "Base" are NOT visible in the template definition itself, because there is no guarantee that "Base" will be an instantiation of the template "Base". It could be an instantiation of an explicit or partial specialization. The actual template from which "Base" is instantiated depeends on "T", which isn't known until Derived is instantiated. In fact, "Base" might not even have a member "fBase" for a particular "T". Some existing commercial compilers get this wrong. They are attempting to compile older code written before the template rules were completely written (when templates were more like macros). But such compilers can actually generate incorrect code, and they encourage people to continue writing ill-formed code such as that above. So in my opinion vendors which supply compilers that accept such cod are not doing their customers a favor. -- Bill Gibbons bill@gibbons.org [ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]