设为首页 加入收藏

TOP

C++操作符重载不同方式区别
2014-11-14 15:00:26 来源: 作者: 【 】 浏览:13
Tags:操作 重载 不同 方式 区别

  C++ 编程语言可以被看做是C语言的升级版本,它能够支持C语言中的所有功能,而且在其他方面也有很大的提升。其中,在C++操作符重载中++,--需要说明是++(--)在操作数前面,还是在操作数后面,区别如下:


  C++操作符重载代码经过测试无误(起码我这里没问题^_^)


  1.#include < iostream>


  2.#include < cstdlib>


  3.using namespace std;


  4.template< typename T> class A


  5.{


  6.public:


  7.A(): m_(0){


  8.}


  9.// +


  10.const T operator + (const T& rhs)


  11.{


  12.// need to be repaired , but see it is only a demo


  13.return (this->m_ + rhs);


  14.}


  15.// -


  16.const T operator - (const T& rhs){


  17.// need to be repaired , but see it is only a demo


  18.return (this->m_ - rhs);


  19.}


  20.T getM(){


  21.return m_;


  22.}


  23.// ++在前的模式,这里返回的是引用 ,准许++++A


  24.A& operator ++ (){


  25.(this->m_)++;


  26.return *this;


  27.}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++二维动态数组 下一篇C++断点无效解决方案

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: