Noah Roberts wrote:
This isn't possible?
template < typename SUB >
struct Base
{
typedef typename SUB::dim dimen;
};
struct Sub : Base<Sub>
{
typedef int dim;
};
I was pretty sure it could be done.
So was I. I can almost see, in my mind, the page where Stroustrup gives
an example of it in The C++ Programming Language, Third Edition. Well,
apart from the typedef in the class template, anyway.
I did try a variation:-
[Start C++ snippet.]
template<typename SUB, typename DIM = SUB::dimstruct Base {
typedef DIM dimen;
};
[End C++ snippet.]
but that didn't work, either. It's not hard to imagine why, as, when
that default parameter argument is used explicitly, you have:-
[Start C++ snippet.]
struct Sub : Base<Sub, Sub::dim{
typedef int dim;
};
[End C++ snippet.]
which obviously won't work. Maybe there's a connection?
But yours really ought to work, oughtn't it? Or is it because the
compiler's trying to establish what the base part of Sub is, in detail,
in the course of establishing what Sub is, but finding that to do that,
it's got to establish what Sub is, in enough detail, in order to
establish what the base part of it is? I suspect that that might be it
- but it's only a suspicion.
--
Simon G Best
What happens if I mention Leader Kibo in my .signature?