网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

C++开发之实现操作符重载的实例-创新互联

C++操作符重载

成都创新互联10多年成都企业网站建设服务;为您提供网站建设,网站制作,网页设计及高端网站定制服务,成都企业网站建设及推广,对混凝土搅拌罐等多个领域拥有多年的网站运维经验的网站建设公司。

实现效果图:

C++ 开发之实现操作符重载的实例

实例代码:

Matrix.h

#pragma once 
#include "vector" 
#include "iostream" 
#define rep(i,n) for(int i=1;i<=n;i++) //宏定义for循环,精简代码 
using namespace std; 
class Matrix 
{ 
public: 
  //基本构造函数 
  Matrix(int Row=0, int Column=0); 
  //拷贝构造函数或者复制构造函数 
  Matrix(const Matrix& matrix); 
  //赋值操作符重载,必须为成员函数,不然会报错 
  Matrix& operator=(const Matrix& matrix); 
  //复合赋值操作符重载,建议重载为成员函数 
  Matrix& operator+=(const Matrix& matrix); 
  Matrix& operator*=(const Matrix& matrix); 
  Matrix& operator*=(const float& number); 
  Matrix& operator*=(const int& number); 
  Matrix& operator-=(const Matrix& matrix); 
  Matrix& operator/=(const float& number); 
  float& operator[](const size_t& index); 
  Matrix& operator++();//前缀式自增 
  Matrix& operator--();//前缀式自减 
  Matrix operator++(int); //后缀式自增 
  Matrix operator--(int); //后缀式自减 
  //算术和关系操作符一般为非成员函数,声明为友元 
  friend Matrix operator+(const Matrix& matrix1, const Matrix& matrix2); 
  friend Matrix operator-(const Matrix& matrix1, const Matrix& matrix2); 
  friend Matrix operator*(const Matrix& matrix1, const Matrix& matrix2); 
  friend Matrix operator*(const Matrix& matrix1, const float& number); 
  friend Matrix operator*(const Matrix& matrix1, const int& number); 
  friend bool operator==(const Matrix& matrix1, const Matrix& matrix2); 
  friend bool operator!=(const Matrix& matrix1, const Matrix& matrix2); 
  //输出操作符<<的重载,必须声明为友元 
  friend ostream& operator<<(ostream& os, const Matrix&object); 
  //输入操作符>>重载,必须声明为友元 
  friend istream& operator >>(istream& in,Matrix&object); 
  void Display(); 
  ~Matrix(); 
public: 
  int Row; 
  int Column; 
  vector > data; //二维vector,用于存放矩阵类数据 
};

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章题目:C++开发之实现操作符重载的实例-创新互联
文章网址:http://bjjierui.cn/article/epojc.html

其他资讯