/*******************************************************
*author:彭晓林
*copyright: 版权所有,翻版不究
*function: ++运算符前置重载
******************************************************/
#include <iostream>
#include <string>
using namespace std;
class DEMO
{
public:
DEMO(int a)
{
x = 1;
}
void set(int a)
{
x = a;
}
void operator++(){++x;}
void print();
private:
int x;
};
void DEMO::print()
{
cout<<"x = "<<x<<endl;
}
int main()
{
DEMO test(1);
test.print();
++test;
test.print();
while(1);
}s
本文介绍了一个简单的C++程序示例,展示了如何实现类成员中前置++运算符的重载。通过一个名为DEMO的类,演示了自增运算符的使用方法及其对类内部数据成员的影响。
9101

被折叠的 条评论
为什么被折叠?



