next up previous
Next: Missing Typedef Bug (section Up: Error Messages Previous: Error Messages

Upcasting Bug (section )

The upcasting bug has also been known to cause an exception to be thrown. This occured in the following piece of code:

template <class Qtype>
ostream& operator<< (ostream &os, const Quantum<Qtype> &ku) {
    os << ku.qVal;
    return os;
}
where ku.qVal could be a Double or a Vector<Double> (but the operator<< function is defined for Arrays not Vectors). The compiler did not detect that there was an upcasting problem and examination with a debugger revealed it was getting into an infinite constructor loop! Further investigation revealed that the compiler did not find a function match using an upcast but was able to find another unintended match, that was further resolved to the original function!



Ralph Marson
Wed Aug 28 17:15:27 MDT 1996