Topic: Improved example in 14.6.2 [2]
Author: sgganesh@gmail.com
Date: Tue, 11 Oct 2005 16:45:55 CST Raw View
In 14.6.2[2], the template class B is not provided and the reader has
to imagine what it should have been.
template<class T> struct X : B<T> {
typename T::A* pa;
void f(B<T>* pb) {
static int i = B<T>::i;
pb->j++;
}
};
How about adding the definition of B before X:
template <class U> class B {
int i;
int j;
};
(I know, I know, Standard text is not meant for beginners, but IMHO, it
doesn't hurt if the programs are more descriptive to avoid ambiguity).
Thanks!
-Ganesh
---
[ 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 Ganesh Barbati)
Date: Tue, 11 Oct 2005 23:20:32 GMT Raw View
sgganesh@gmail.com wrote:
> In 14.6.2[2], the template class B is not provided and the reader has
> to imagine what it should have been.
>
> template<class T> struct X : B<T> {
> typename T::A* pa;
> void f(B<T>* pb) {
> static int i = B<T>::i;
> pb->j++;
> }
> };
>
> How about adding the definition of B before X:
>
> template <class U> class B {
> int i;
> int j;
> };
>
> (I know, I know, Standard text is not meant for beginners, but IMHO, it
> doesn't hurt if the programs are more descriptive to avoid ambiguity).
>
The intent of this section is to show that binding of dependent names is
deferred to the point of instantiation. Giving a complete definition of
class template B bearing members i and j conveys the wrong message,
because the reader can be misled into thinking that bindind might occur
at point of declaration. If you really think a declaration of B is
necessary, I would use a forward declaration instead:
template <class U> class B;
so when it comes to "B<T>::i" I can say "Oh, wow! I can name members of
B<T> even if I did not declare them yet! That's two-phase binding!".
Just my opinion,
Ganesh
---
[ 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 ]