#include"aa.h"
#include<iostream.h>
#include<stdio.h>
#include<string.h>
class bb
{
public:
char *i;
bb ()
{this->i=0;
cout<<("no pram!\n");
}
bb (bb &b)//
{this->i=new char[10];
strcpy(this->i,b.i);
cout<<("深度复制!\n");
}
bb (char *i)//深度复制
{this->i=new char[10];
strcpy(this->i,i);
cout<<("with pram!\n");
}
~bb()//析构函数
{
if(0!=this->i)
delete this->i;
cout<<("destry!\n");
}
bb & operator=(bb &b)//对于要不要反悔值,是看如果在main中a=a1,就不要返回会也可以,如果是这样的a=a1=a2,就则就
定要反回值
{
this->i=new char[10];
strcpy(this->i,b.i);
return *this;
}
void operator ++()
{
(*this->i)++;
}
};
ostream & operator<<(ostream &b1,bb &b2)
{
b1<<b2.i<<endl;
return b1;
}
void operator>>(istream &b1,bb &b2)
{
b2.i=new char[10];
b1>>b2.i;
}
int main()
{
bb a1;
// a1=a;
// bb a2=a1;
cin>>a1;
a1++;
cout<<a1;
return 0;
}
其实++这里就是函数,在c里++,就是+1,
如果这里输入aa,则执行后就变成ba,
#include"aa.h"
#include<iostream.h>
#include<stdio.h>
#include<string.h>
class bb
{
public:
char *i;
int j;
bb ()
{this->j=0;
this->i=0;
cout<<("no pram!\n");
}
bb (bb &b)//
{this->i=new char[10];
strcpy(this->i,b.i);
cout<<("深度复制!\n");
}
bb (char *i)//深度复制
{this->i=new char[10];
strcpy(this->i,i);
cout<<("with pram!\n");
}
~bb()//析构函数
{
if(0!=this->i)
delete this->i;
cout<<("destry!\n");
}
bb & operator=(bb &b)//对于要不要反悔值,是看如果在main中a=a1,就不要返回会也可以,如果是这样的a=a1=a2,就则就
定要反回值
{
this->i=new char[10];
strcpy(this->i,b.i);
return *this;
}
int operator ++()//前缀
{
return this->j++;
}
int operator ++(int)//后缀
{
int temp=this->j;
this->j++;
return temp;
}
};
ostream & operator<<(ostream &b1,bb &b2)
{
b1<<b2.i<<endl;
return b1;
}
void operator>>(istream &b1,bb &b2)
{
b2.i=new char[10];
b1>>b2.i;
}
int main()
{
int j;
bb a1;
j=++a1;//前缀
cout<<j<<endl;
j=a1++;//后缀
cout<<j<<endl;
return 0;
}
[]重载
#include"aa.h"
#include<iostream.h>
#include<stdio.h>
#include<string.h>
class bb
{
public:
char *i;
int j;
bb ()
{this->j=0;
this->i=0;
cout<<("no pram!\n");
}
bb (bb &b)//
{this->i=new char[10];
strcpy(this->i,b.i);
cout<<("深度复制!\n");
}
bb (char *i)//深度复制
{this->i=new char[10];
strcpy(this->i,i);
cout<<("with pram!\n");
}
~bb()//析构函数
{
if(0!=this->i)
delete this->i;
cout<<("destry!\n");
}
bb & operator=(bb &b)//对于要不要反回值,是看如果在main中a=a1,就不要返回会也可以,如果是这样的a=a1=a2,就则就定要反回值
{
this->i=new char[10];
strcpy(this->i,b.i);
return *this;
}
int operator ++()//前缀
{
return this->j++;
}
int operator ++(int)//后缀
{
int temp=this->j;
this->j++;
return temp;
}
char operator [](int i1)
{
return this->i[i1];
}
};
ostream & operator<<(ostream &b1,bb &b2)
{
b1<<b2.i<<endl;
return b1;
}
void operator>>(istream &b1,bb &b2)
{
b2.i=new char[10];
b1>>b2.i;
}
int main()
{
bb a1;
cin>>a1;
char ch=a1[2];
cout<<ch;
return 0;
}
#include<iostream.h>
#include<stdio.h>
#include<string.h>
class bb
{
public:
char *i;
bb ()
{this->i=0;
cout<<("no pram!\n");
}
bb (bb &b)//
{this->i=new char[10];
strcpy(this->i,b.i);
cout<<("深度复制!\n");
}
bb (char *i)//深度复制
{this->i=new char[10];
strcpy(this->i,i);
cout<<("with pram!\n");
}
~bb()//析构函数
{
if(0!=this->i)
delete this->i;
cout<<("destry!\n");
}
bb & operator=(bb &b)//对于要不要反悔值,是看如果在main中a=a1,就不要返回会也可以,如果是这样的a=a1=a2,就则就
定要反回值
{
this->i=new char[10];
strcpy(this->i,b.i);
return *this;
}
void operator ++()
{
(*this->i)++;
}
};
ostream & operator<<(ostream &b1,bb &b2)
{
b1<<b2.i<<endl;
return b1;
}
void operator>>(istream &b1,bb &b2)
{
b2.i=new char[10];
b1>>b2.i;
}
int main()
{
bb a1;
// a1=a;
// bb a2=a1;
cin>>a1;
a1++;
cout<<a1;
return 0;
}
其实++这里就是函数,在c里++,就是+1,
如果这里输入aa,则执行后就变成ba,
#include"aa.h"
#include<iostream.h>
#include<stdio.h>
#include<string.h>
class bb
{
public:
char *i;
int j;
bb ()
{this->j=0;
this->i=0;
cout<<("no pram!\n");
}
bb (bb &b)//
{this->i=new char[10];
strcpy(this->i,b.i);
cout<<("深度复制!\n");
}
bb (char *i)//深度复制
{this->i=new char[10];
strcpy(this->i,i);
cout<<("with pram!\n");
}
~bb()//析构函数
{
if(0!=this->i)
delete this->i;
cout<<("destry!\n");
}
bb & operator=(bb &b)//对于要不要反悔值,是看如果在main中a=a1,就不要返回会也可以,如果是这样的a=a1=a2,就则就
定要反回值
{
this->i=new char[10];
strcpy(this->i,b.i);
return *this;
}
int operator ++()//前缀
{
return this->j++;
}
int operator ++(int)//后缀
{
int temp=this->j;
this->j++;
return temp;
}
};
ostream & operator<<(ostream &b1,bb &b2)
{
b1<<b2.i<<endl;
return b1;
}
void operator>>(istream &b1,bb &b2)
{
b2.i=new char[10];
b1>>b2.i;
}
int main()
{
int j;
bb a1;
j=++a1;//前缀
cout<<j<<endl;
j=a1++;//后缀
cout<<j<<endl;
return 0;
}
[]重载
#include"aa.h"
#include<iostream.h>
#include<stdio.h>
#include<string.h>
class bb
{
public:
char *i;
int j;
bb ()
{this->j=0;
this->i=0;
cout<<("no pram!\n");
}
bb (bb &b)//
{this->i=new char[10];
strcpy(this->i,b.i);
cout<<("深度复制!\n");
}
bb (char *i)//深度复制
{this->i=new char[10];
strcpy(this->i,i);
cout<<("with pram!\n");
}
~bb()//析构函数
{
if(0!=this->i)
delete this->i;
cout<<("destry!\n");
}
bb & operator=(bb &b)//对于要不要反回值,是看如果在main中a=a1,就不要返回会也可以,如果是这样的a=a1=a2,就则就定要反回值
{
this->i=new char[10];
strcpy(this->i,b.i);
return *this;
}
int operator ++()//前缀
{
return this->j++;
}
int operator ++(int)//后缀
{
int temp=this->j;
this->j++;
return temp;
}
char operator [](int i1)
{
return this->i[i1];
}
};
ostream & operator<<(ostream &b1,bb &b2)
{
b1<<b2.i<<endl;
return b1;
}
void operator>>(istream &b1,bb &b2)
{
b2.i=new char[10];
b1>>b2.i;
}
int main()
{
bb a1;
cin>>a1;
char ch=a1[2];
cout<<ch;
return 0;
}