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>
s.Matrix
. External functions have not and cannot be this and, therefore, no fields of the object in scope functions.ostream&operator <<(ostream&s,const matrix<t>&n)</t>
Find more questions by tags C++