C++的++重载

++重载主要要考虑到前增量和后增量的区别。
class A
{
int t;
public:
A& operator++(); //前缀
A operator ++(int); //后缀
}
A& A::operator++()
{
++t;
return *this;
}
A A::operator++(int)
{
A a=*this;
++t;
return a;
}

This entry was posted in Program and tagged . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please copy the string BorAgR to the field below:

以新浪微博帐号登录