Comparison chart of D and C++ templates
Yauheni Akhotnikau
eao197 at intervale.ru
Fri Jan 19 06:36:15 PST 2007
On Fri, 19 Jan 2007 13:02:47 +0300, Walter Bright
<newshound at digitalmars.com> wrote:
> http://www.digitalmars.com/d/template-comparison.html
>
> Comments?
In the sample:
template<class T>
class Foo
{
typedef int A;
};
template<class T>
class Bar : Foo<T>
{
A x; // error
};
it's more correctly to use protected or public keyword in Foo, I think:
template<class T>
class Foo
{
protected:
typedef int A;
};
because in original code A is a private member of Foo and cannot be
accessed from derived classes.
And a question. It's necessary to use 'typename T<U>::' in C++ to access
to typedef in some template class. Even when classes are not related as
base/derived:
template< class T >
struct Iterator
{
typedef T value_type;
typedef T * pointer_type;
};
template< class I >
struct IteratorAdapter
{
typename Iterator< I >::pointer_type ptr;
};
int
main()
{
IteratorAdapter< int > a;
}
I think the same situation is in your sample, because Foo<T> is a template
class and it is necessary to use 'typename Foo<T>::' as a prefix for A in
Base. So, do you think your sample 'Dependent Base Class Lookup' is
correct in this context? May be better to speak about access to
typedefs/alias in D's templates without 'typename' keyword?
--
Regards,
Yauheni Akhotnikau
More information about the Digitalmars-d-announce
mailing list