Why not see the operator overloading of the output stream?

hi all!

Actually trying to make a container class, but for some reason the program use Android trainer for running.
The same when overloading operator << doesn't see class variables

using namespace std;

template <typename t>
class matrix
{
private:
 T* Matrix;
 int _col;
public:

 class Iterator;
 matrix(int n=1):_col(n)
{
 Matrix=new T[n];
}
 T&operator[](const int&n)
{
if(n>0&&n<_col)
 return Matrix[n];
}
 Iterator begin(){return Matrix;}
 Iterator end(){return Matrix+_col;}
 friend ostream&operator <<(ostream&s,const matrix<t>&n);
 class Iterator
{
public:
T*cur;
Iterator(T*first):cur(first)
{}
 T&operator +(int n){return *(cur+n);}
 T&operator -(int n){return *(cur-n);}
 T&operator ++(int){return *cur++;}
 T&operator --(int){return *--cur;}
 T&operator ++(){return *cur++;}
 T&operator --(){return *--cur;}
 bool operator != (const Iterator&it){return cur!=it.cur;}
 bool operator ==(const Iterator&it){return cur==it.cur;}
 T& operator*(){return *cur;}
};
};
ostream&operator <<(ostream&s,const matrix<t>&n)
{
 s<<matrix[n]; return s; }< code></matrix[n];></t></t></typename>
br><br><pre><code class="cpp">int main() { matrix <char*>Matrix(3); Matrix[0]="str1"; Matrix[1]="str2"; Matrix[3]="str2"; auto it=matrix<char*>::Iterator(Matrix.begin()); while(it!=Matrix.end()) { cout<<*it<<endl; it++; } _getch(); return 0; }< code></endl;></char*></char*></code></pre>
June 10th 19 at 15:51
2 answers
June 10th 19 at 15:53
Because you implement the operator << in the form of an external function, and when accessing fields of the object need to specify a specific object instance, for example s.Matrix. External functions have not and cannot be this and, therefore, no fields of the object in scope functions.
June 10th 19 at 15:55
ostream&operator <<(ostream&s,const matrix<t>&n)</t>

The second parameter of this function -- the template. Where will it T?

Find more questions by tags C++