单目运算符重载为成员函数 前++ 和后++的使用
2014-06-11 02:34
323 查看
//单目运算符重载为成员函数 后++ 采用了哑元 #include<iostream> using namespace std; class CPoint { private: int x,y; public: CPoint(int a = 0,int b = 0){ x = a; y = b; } CPoint operator++(int); void display(); }; CPoint CPoint::operator++(int){ x++; y++; return *this; } void CPoint::display(){ cout << x << " " << y << endl; } int main(void){ CPoint p; p++; p.display(); return 0; } //单目运算符重载为成员函数 前++ #include <iostream> using namespace std; class CPoint { private: int x,y; public: CPoint(int a = 0,int b = 0){ x = a; y = b; } CPoint operator++(); void display(); }; CPoint CPoint::operator++(){ x++; y++; return *this; } void CPoint::display(){ cout << x << " " << y << endl; } int main(void){ CPoint p; ++p; p.display(); return 0; }
相关文章推荐
- 将单目运算符“++”重载为成员函数形式
- 单目运算符“++”重载为成员函数形式
- 将单目运算符“++”重载为成员函数形式
- Static静态成员函数的使用
- 高质量C++成员函数的重载、覆盖与隐藏
- 子类重载父类的非虚成员函数是否对从父类中继承且使用该成员函数的方法的行为产生影响
- 重载成员函数使CAsyncSocket类支持IPX/SPX协议
- C++ 成员函数的重载、覆盖与隐藏
- C++中使用非静态成员函数代替全局函数
- 使用成员函数访问私有数据成员
- 类的const和非const成员函数的重载
- 类成员函数的重载、覆盖和隐藏区别
- 大胆使用指向成员函数的指针
- [zz]成员函数的重载、覆盖与隐藏
- MFC-CString类及其成员函数使用实例
- Effective STL: Item 44:优先使用与泛型算法同名的成员函数
- 成员函数的重载、覆盖与隐藏
- C# 使用重载消息处理函数的方式,实现没有标题栏的窗体的拖动。
- 成员函数的重载、覆盖与隐藏
- 如何得到类成员函数的指针(操作符.×和->*的使用)