class CInt { public:CInt(int n) {m_Value = n;} CInt& operator++() { m_Value = m_Value + 1; return *this; } const CInt operator++(int) { CInt oldValue(m_Value); m_Value = m_Value + 1; return oldValue; } protected:private:int m_Value; }; int _tmain(int

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/11 00:07:24
class CInt { public:CInt(int n) {m_Value = n;} CInt& operator++() { m_Value = m_Value + 1; return *this; } const CInt operator++(int) { CInt oldValue(m_Value); m_Value = m_Value + 1; return oldValue; } protected:private:int m_Value; }; int _tmain(int

class CInt { public:CInt(int n) {m_Value = n;} CInt& operator++() { m_Value = m_Value + 1; return *this; } const CInt operator++(int) { CInt oldValue(m_Value); m_Value = m_Value + 1; return oldValue; } protected:private:int m_Value; }; int _tmain(int
class CInt
{
public:
CInt(int n) {m_Value = n;}
CInt& operator++()
{
m_Value = m_Value + 1;
return *this;
}
const CInt operator++(int)
{
CInt oldValue(m_Value);
m_Value = m_Value + 1;
return oldValue;
}
protected:
private:
int m_Value;
};
int _tmain(int argc,_TCHAR* argv[])
{
CInt test(1);
test++;//后缀自增
++test;//前缀自增
return 0;
}
主要第五行和第八行和第八行一下!(不懂)

class CInt { public:CInt(int n) {m_Value = n;} CInt& operator++() { m_Value = m_Value + 1; return *this; } const CInt operator++(int) { CInt oldValue(m_Value); m_Value = m_Value + 1; return oldValue; } protected:private:int m_Value; }; int _tmain(int
class CInt /*类定义,类名*/
{
public:/*访问权限,这种类型谁都可以访问*/
CInt(int n) {m_Value = n;} /*构造函数,当你用此类声明类对象里就调用此函数.如无此定义,那么系统会自动生成一个构造函数并隐藏*/
CInt& operator++() /*运算符重载前自增,返回一个CInt类的引用,引用同样只是类对象的一个同意名词而矣*/
{
m_Value = m_Value + 1;
return *this; /*返回本身内容,注意this指针指向的是类对象自己*/
}
const CInt operator++(int) /*运算符重载后自增,int只作为一个标识而矣.在之前的const表明该函数不能改变该类的任何,但并不是该类不能改变*/
{
CInt oldValue(m_Value); /*这儿就调用了之前定义的构造函数*/
m_Value = m_Value + 1;
return oldValue; /*返回类对象*/
}
protected:/*权限为保护,此权限在继续时用得上*/
private:/*私有权限,除了自己谁也不能访问该类型成员*/
int m_Value;
};
int _tmain(int argc,_TCHAR* argv[])
{
CInt test(1);
test++;//后缀自增 ,调用成员运算符重载函数
++test;//前缀自增 ,调用成员运算符重载函数
return 0;
}