www.digitalmars.com         C & C++   DMDScript  

c++ - spurious 'friend' causes internal error

In the code below a cut-and-paste error put a spurious 'friend' in a function
definition.
The compiler exits with "Internal error: template 1412" instead of an error
message.

#include <iostream.h>

template <typename T>
class pair {
    T val1, val2;
public:
    pair (T a, T b): val1(a), val2(b) {}
    T first() {return val1;}
    T second() {return val2;}
    template <typename T>
        friend ostream& operator << (ostream& os, pair<T> const& p);
};


// the 'friend' below is an error
template <typename T>
friend ostream& operator << (ostream& os, pair<T> const& p)
{
    return os << p.val1 << ',' << p.val2;
}

int main()
{
    pair<int> p(1,2);
    cout << p << '\n';
}
Jun 08 2003