65,211
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class Number
{
public :
Number() throw();
~Number() throw();
Number(const Number& n) throw();
Number& operator=(const Number&n) throw();
Number& operator++() throw();
Number operator++ (int) throw();
};
Number::Number() throw()
{}
Number::~Number() throw()
{
cout <<"dtor";
}
Number::Number(const Number& n) throw() //产生Number的两个拷贝
{
cout <<"copy";
}
/*Number& Number::operator=(const Number& n) throw()
{
cout <<"assign"; return *this;
} */
Number& Number::operator=(const Number& n) throw()
{
cout <<"increament"; return *this;
}
Number & Number::operator++ () throw()
{
cout<<"++Number"<<endl;
return *this;
}
Number Number::operator++ (int) throw()
{
Number old=*this;
++(*this);
return old; //返回局部变量old
}
int main()
{
Number n;
cout <<"++n: ";
++n;
cout <<'\n';
cout <<" n++: ";
n++;
cout <<'\n';
}
#include <iostream>
using namespace std;
class Number
{
public :
Number() throw();
~Number() throw();
Number(const Number& n) throw();
Number& operator=(const Number&n) throw();
Number& operator++() throw();
Number operator++ (int) throw();
};
Number::Number() throw()
{}
Number::~Number() throw()
{
cout <<"dtor";
}
Number::Number(const Number& n) throw() //产生Number的两个拷贝
{
cout <<"copy";
}
/*Number& Number::operator=(const Number& n) throw() //这个重复了;
{
cout <<"assign"; return *this;
} */
Number& Number::operator=(const Number& n) throw()
{
cout <<"increament"; return *this;
}
Number & Number::operator++ () throw() //这个未定义;
{
cout<<"++Number"<<endl;
return *this;
}
Number Number::operator++ (int) throw()
{
Number old=*this;
++(*this);
return old; //返回局部变量old
}
int main()
{
Number n;
/*cout <<"++n: ";
++n;*/
cout <<'\n';
cout <<" n++: ";
n++;
cout <<'\n';
}