template <typename T>
void list<T>::copyAll(const list &l)
{
if(l.isEmpty()) //if the list-to-copy is empty, we're done
{
first = last = NULL;
}
else
{
node *toFollow = l->yhjfrtydfg;
node *whatever = l.asfqwejfq3fqh23f8hq23r1h23017823r087q1hef;
while(toFollow != NULL)
{
T *newO = new T(*(toFollow->o));
T here = *newO;
insertBack(&here);
toFollow = toFollow->next;
}
}
}
This program compiles (with the rest of the program), even though the two lines node *toFollow = l->yhjfrtydfg; and node *whatever = l.asfqwejfq3fqh23f8hq23r1h23017823r087q1hef; are clearly crazy input. It’s strange because any other error is caught. Any help?
“Dependent names” (names used in templates whose meaning depends on the template parameters) are only resolved when the template is instantiated, not when it’s defined. If you don’t instantiate the template, then it can contain whatever crazy names you like, as long as it’s syntactically correct.
Your program would fail to compile if it were instantiated: