Give an algorithm for recognizing floating-point numbers.
d represents one of the decimal digits 0 through 9. This recognizer reads through the character sequence until if finds the first floating-point number, then it stops. The sign is taken care of in the Start state.![]()
The problem with handling an error at the low level in which it occurs is the library routine that detects the error doesn't have enough information to sensibly handle the error. The best source of error handling information is the caller of the library routine, which is why the recommendation is to pass an error indicator back to the caller.
Eager splitting divides the input line into comma separated values as soon as the source line is input. Lazy splitting divides the source line into comma separated values only when a particular comma separated value is needed.
Lazy splitting has the advantage performing work only when work is required, and so may be more efficient in execution. The disadvantage of lazy splitting is the bookkeeping that's required to keep track of which parts of the input line have been split and which parts need to be split; lazy splitting is also more complex to implement than is eager splitting.
is the usual templated stack implementation and the classestemplate <class ElementType> class Stack { . . . };
Prnt
and
Chld
are defined as
What your colleague doesn't understand is why the declarationclass Prnt { . . . }; class Chld : public Prnt { . . . };
produces a type error. What explanation do you give to your colleague?Stack<Prnt> * prnt_ptr = new Stack<Chld>;
Your colleague seems to be confusing the template class with the template
parameter classes. The Stack
template class does not inherit from any
other class, so each instantiation Stack<T>
has no relation to any
other instantiation except to another Stack<T>
instantiation, with
which it's type equivalent. Any relation other than equality between
template-parameter classes has no influence on the relation between template
instances. Two template instantiations, each with a different actual template
parameter type, are different from one another.
A number of people answered the question by referring to the strict type matching done by template parameters. While that's true, it has nothing to do with this problem; strict type matching for template parameters only affects any particular template instantiation; it doesn't affect the relation (apart from equality) between template instantiations (and, strict template matching only becomes an issue in a single instantiation when trying to unify a single template parameter with two (or more) actual template parameter of differing types).
This page last modified on 15 February 2001.