template friend function cannot access private member
<p>I am trying to compile the program on the book  3rd edition on vc6. It sees those 3 friend functions cannot access the private members. I have removed the &lt;> after the operator== in the friend function declaration since it cannot pass the syntax check. </p>

<p>This might be a well-known problem, I guess it might be due to the friend function name mismatch, but I just do not know how to correct it. Kindly help me on this. Thanks
The code is below:</p>

<pre><code>   // Program to test slices and a simple N*M matrix class

// pp 670-674 and 683-684

// No guarantees offered. Constructive comments to bs@research.att.com


#include&lt;iostream&gt;
#include&lt;valarray&gt;
#include&lt;algorithm&gt;
#include&lt;numeric&gt;   // for inner_product
using namespace std;

// forward declarations to allow friend declarations:
template&lt;class T&gt; class Slice_iter;
template&lt;class T&gt; bool operator==(const Slice_iter&lt;T&gt;&amp;, const Slice_iter&lt;T&gt;&amp;);
template&lt;class T&gt; bool operator!=(const Slice_iter&lt;T&gt;&amp;, const Slice_iter&lt;T&gt;&amp;);
template&lt;class T&gt; bool operator&lt; (const Slice_iter&lt;T&gt;&amp;, const Slice_iter&lt;T&gt;&amp;);

template&lt;class T&gt; class Slice_iter {
    valarray&lt;T&gt;* v;
    slice s;
    size_t curr;    // index of current element

    T&amp; ref(size_t i) const { return (*v)[s.start()+i*s.stride()]; }
public:
    Slice_iter(valarray&lt;T&gt;* vv, slice ss) :v(vv), s(ss), curr(0) { }

    Slice_iter end() const
    {
        Slice_iter t = *this;
        t.curr = s.size();  // index of last-plus-one element
        return t;
    }

    Slice_iter&amp; operator++() { curr++; return *this; }
    Slice_iter operator++(int) { Slice_iter t = *this; curr++; return t; }

    T&amp; operator[](size_t i) { return ref(i); }      // C style subscript
    T&amp; operator()(size_t i) { return ref(i); }      // Fortran-style subscript
    T&amp; operator*() { return ref(curr); }            // current element

    friend bool operator==(const Slice_iter&lt;T&gt;&amp; p, const Slice_iter&lt;T&gt;&amp; q);
    friend bool operator!=(const Slice_iter&lt;T&gt;&amp; p, const Slice_iter&lt;T&gt;&amp; q);
    friend bool operator&lt; (const Slice_iter&lt;T&gt;&amp; p, const Slice_iter&lt;T&gt;&amp; q);

};


template&lt;class T&gt;
bool operator==(const Slice_iter&lt;T&gt;&amp; p, const Slice_iter&lt;T&gt;&amp; q)
{
    return p.curr==q.curr &amp;&amp; p.s.stride()==q.s.stride() &amp;&amp; p.s.start()==q.s.start();
}

template&lt;class T&gt;
bool operator!=(const Slice_iter&lt;T&gt;&amp; p, const Slice_iter&lt;T&gt;&amp; q)
{
    return !(p==q);
}

template&lt;class T&gt;
bool operator&lt;(const Slice_iter&lt;T&gt;&amp; p, const Slice_iter&lt;T&gt;&amp; q)
{
    return p.curr&lt;q.curr &amp;&amp; p.s.stride()==q.s.stride() &amp;&amp; p.s.start()==q.s.start();
}
</code></pre>

<p>since I cannot add a lot text to comments, I posted some errors in vs2008. It is quite clear that the previous error is due to the vc6, thanks a lot.
complete code is at here:http://www2.research.att.com/~bs/matrix.c It seems those syntax error is not related to the friend function, but the inner_product in numeric. 
some error message under visual studio 2008:</p>

<pre><code>1&gt;c:\vc2008\vc\include\xutility(764) : error C2039: 'iterator_category' : is not a member of 'Cslice_iter&lt;T&gt;'
1&gt;        with
1&gt;        [
1&gt;            T=double
1&gt;        ]
1&gt;        c:\vc2008\vc\include\numeric(106) : see reference to class template instantiation 'std::iterator_traits&lt;_Iter&gt;' being compiled
1&gt;        with
1&gt;        [
1&gt;            _Iter=Cslice_iter&lt;double&gt;
1&gt;        ]
1&gt;        k:\c++\valarray0.cpp(245) : see reference to function template instantiation 'double std::inner_product&lt;Cslice_iter&lt;T&gt;,_Ty*,double&gt;(_InIt1,_InIt1,_InIt2,_Ty)' being compiled
1&gt;        with
1&gt;        [
1&gt;            T=double,
1&gt;            _Ty=double,
1&gt;            _InIt1=Cslice_iter&lt;double&gt;,
1&gt;            _InIt2=double *
1&gt;        ]
1&gt;c:\vc2008\vc\include\xutility(764) : error C2146: syntax error : missing ';' before identifier 'iterator_category'
1&gt;c:\vc2008\vc\include\xutility(764) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1&gt;c:\vc2008\vc\include\xutility(764) : error C2602: 'std::iterator_traits&lt;_Iter&gt;::iterator_category' is not a member of a base class of 'std::iterator_traits&lt;_Iter&gt;'
1&gt;        with
</code></pre>
