Boost logo

Boost :

From: scleary_at_[hidden]
Date: 2002-11-05 15:55:40

> From: David A. Greene [mailto:greened_at_[hidden]]
> scleary_at_[hidden] wrote:
> >>From: David A. Greene [mailto:greened_at_[hidden]]
> >>
> >><snip>
> >>
> >>Nowhere is "decrement" declared or defined in the filter_iterator
> >>policies yet it can still be used with iterator_adaptor. How
> >>does this work? Shouldn't the compiler complain that
> >>iterator_adaptor::operator--() can't find
> >>filter_iterator_policies::decrement? I could understand if
> >>operator-- were a template member but it's not. I'm obviously
> >>missing something. What is it?
> >
> >
> > Well, it's not really "used" by iterator_adaptor. Since
iterator_adaptor is
> > a template class, the compiler will not instantiate its member functions
> > unless they are actually used (i.e., called). This is true even though
> > operator-- is not a template member.
> Oh! Well, I learned something new today. I was under the impression
> that when a class template is instantiated all of its non-template
> members are also instantiated.

Just to clarify: when a class template is instantiated, all the
*declarations* of its members are instantiated -- but not the *definitions*
of them. When the compiler instantiates iterator_adaptor, it will
instantiate the declaration of operator--; but, it will not instantiate the
definition of operator-- unless it is used (and the invalid code is
contained in the definition, not the declaration).


Boost list run by bdawes at, gregod at, cpdaniel at, john at