当前位置: 首页 > news >正文

建设数据库网站需要哪些设备seo平台优化服务

建设数据库网站需要哪些设备,seo平台优化服务,朝阳网站建设是什么意思,wordpress 足迹地图目录 1.定义友元运算符重载函数的语法形式 2.双目运算符重载 3.单目运算符重载 1.定义友元运算符重载函数的语法形式 (1)在类的内部,定义友元运算符重载函数的格式如下: friend 函数类型 operator 运算符(形参表&a…

目录

1.定义友元运算符重载函数的语法形式

2.双目运算符重载

3.单目运算符重载


1.定义友元运算符重载函数的语法形式

        (1)在类的内部,定义友元运算符重载函数的格式如下:

friend 函数类型 operator 运算符(形参表)
{函数体
}

        (2) 在类中,声明友元运算符重载函数原型的格式如下:

class X
{...firend 函数类型 operator 运算符(形参表);...
};

        (3) 在类外,定义友元运算符重载函数的格式如下:

函数类型 operator 运算符(形参表)
{函数体
}

        若友元运算符重载函数重载的是双目运算符,则参数表中有两个操作数;若重载的是单目运算符,则参数表中只有一个操作数。下面予以介绍。

2.双目运算符重载

        双目运算符有两个操作数,通常在运算符的左右两侧,例如3 + 5,24 > 12 等。下面是用友元运算符重载函数进行复数运算的例子。

#include <iostream>using namespace std;class Complex
{
public:Complex(double r = 0, double i = 0);void print();friend Complex operator+(Complex& a, Complex& b); // 声明运算符 + 重载函数friend Complex operator-(Complex& a, Complex& b); // 声明运算符 - 重载函数friend Complex operator*(Complex& a, Complex& b); // 声明运算符 * 重载函数friend Complex operator/(Complex& a, Complex& b); // 声明运算符 / 重载函数
private:double real; // 复数实部double imag; // 复数虚部
};Complex::Complex(double r, double i) // 构造函数
{real = r;imag = i;
}Complex operator+(Complex& a, Complex& b)
{Complex temp;temp.real = a.real + b.real;temp.imag = a.imag + b.imag;return temp;
}Complex operator-(Complex& a, Complex& b)
{Complex temp;temp.real = a.real - b.real;temp.imag = a.imag - b.imag;return temp;
}Complex operator*(Complex& a, Complex& b)
{Complex temp;temp.real = a.real * b.real - a.imag * b.imag;temp.imag = a.real * b.imag + a.imag * b.real;return temp;
}Complex operator/(Complex& a, Complex& b)
{Complex temp;double t;t = 1 / (b.real * b.real + b.imag * b.imag);temp.real = (a.real * b.real + a.imag * b.imag) * t;temp.imag = (b.real * a.imag - a.real * b.imag) * t;return temp;
}void Complex::print()
{cout << real;if (imag > 0)cout << "+";if (imag != 0)cout << imag << 'i' << endl;
}int main()
{Complex A1(2.3, 4.6), A2(3.6, 2.8), A3, A4, A5, A6; // 定义6个Complex类的对象A3 = A1 + A2; // 复数相加A4 = A1 - A2; // 复数相减A5 = A1 * A2; // 复数相乘A6 = A1 / A2; // 复数相除A1.print(); // 输出复数A1A2.print(); // 输出复数A2A3.print(); // 输出复数相加结果A3A4.print(); // 输出复数相减结果A4A5.print(); // 输出复数相乘结果A5A6.print(); // 输出复数相除结果A6return 0;
}

        程序运行结果如下:

3.单目运算符重载

        单目运算符只有一个操作数,如-a, &b, !c, ++p等。

        以下是用友元函数重载单目运算符“-”。

#include <iostream>using namespace std;class Coord
{
public:Coord(int x1 = 0, int y1 = 0){x = x1;y = y1;}friend Coord operator-(Coord &obj); // 声明单目运算符 - 重载函数void print();
private:int x, y;
};Coord operator-(Coord &obj) // 定义单目运算符 - 重载函数
{obj.x = -obj.x;obj.y = -obj.y;return obj;
}void Coord::print()
{cout << "x = " << x << ", y = " << y << endl;
}int main()
{Coord ob1(50, 60), ob2;ob1.print();ob2 = - ob1;ob2.print();return 0;
}

        程序结果如下:

        用友元函数重载单目运算符“++”。

#include <iostream>using namespace std;class Coord
{
public:Coord(int i = 0, int j = 0){x = i;y = j;}friend Coord operator++(Coord &op) // 定义单目运算符 ++ 重载函数{                                  // 采用对象引用作为函数参数++op.x;++op.y;return op;}void print(){cout << "x = " << x << ", y = " << y << endl;}
private:int x, y;
};int main()
{Coord ob(10, 20);ob.print();++ob;ob.print();return 0;
}

        程序结果如下:

 

http://www.mmbaike.com/news/106150.html

相关文章:

  • 网站建设价格热线怎么申请自己的域名
  • 建个站真的是免费的吗健康码防疫核验一体机
  • 厦门做网站seo的杭州推广系统
  • 宁波做网站多少钱东莞网络优化哪家好
  • 医疗电子科技网站建设营销活动怎么做吸引人
  • 建网站一般要多少钱小米的推广软文
  • 电脑做网站服务器WIN7 买个域名搜索引擎网站有哪些
  • 新闻网站建设的任务要求写文章一篇30元兼职
  • 境外网站开发信息流广告哪个平台好
  • 手机网站模板源码下载新闻发布稿
  • 去哪儿网站做宣传多少钱站长工具下载app
  • 巫山网站设计app地推接单平台
  • 网站模板 站长之家app营销十大成功案例
  • 泉州网站建设平台如何做电商新手入门
  • 国内代理ip免费百度seo价格
  • 手机wordpress怎么保存图片外贸网站seo优化
  • 查询建筑企业网站市场营销手段13种手段
  • 网站建设商家百度问答首页
  • java网站项目可做百度搜索关键词排名优化技术
  • 做网站的诈骗公司seo优化自动点击软件
  • 做个网站大概多少钱合肥搜索引擎优化
  • 网站下载的软件怎么安装互联网营销师怎么报名
  • 电子商务网站建设怎么做seo秘籍优化课程
  • 湛江做网站开发张北网站seo
  • 在网站中添加百度地图百度seo规则最新
  • 寻找聊城做网站的公司seo怎么做优化
  • 公司要建立网站要怎么做seo优化公司排名
  • 旅游网站开发指导网站播放视频速度优化
  • 做网站数据库表各字段详情建网站需要哪些步骤
  • 用织梦做网站费用常用的搜索引擎有哪些