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

一个虚拟主机做2个网站网站制作公司有哪些

一个虚拟主机做2个网站,网站制作公司有哪些,wordpress安卓版怎么用,临沂住房和城乡建设厅网站文章目录 运算符重载加号运算符重载成员函数实现运算符重载全局函数实现运算符重载全局函数实现函数重载 左移运算符重载递增运算符重载赋值运算符重载关系运算符重载函数调用运算符重载 运算符重载 对已有的运算符重新进行定义,赋予其另一种功能,以适应…

文章目录

  • 运算符重载
    • 加号运算符重载
      • 成员函数实现运算符重载
      • 全局函数实现运算符重载
      • 全局函数实现函数重载
    • 左移运算符重载
    • 递增运算符重载
    • 赋值运算符重载
    • 关系运算符重载
    • 函数调用运算符重载

运算符重载

  • 对已有的运算符重新进行定义,赋予其另一种功能,以适应不同的数据类型

  • 对于内置的数据类型的表达式的运算符是不可能改变的

  • 不要滥用运算符重载

加号运算符重载

  • 可以计算自定义数据类型

成员函数实现运算符重载

  • 成员函数实现运算符重载的本质 p2.operator(p1)
#include <iostream>using namespace std;class Person{
public:Person(){}Person(int a, int b) {this->a=a;this->b=b;}// 成员函数实现运算符重载Person operator+(const Person& p) {Person temp;temp.a=this->a+p.a;temp.b=this->b+p.b;return temp;}
public:int a;int b;
};void test() {Person p1(10,10);Person p2(10,10);// 成员函数实现运算符重载的本质 p2.operator(p1)Person p3 = p1+p2;cout << "p3.a: " << p3.a << endl;cout << "p3.b: " << p3.b << endl;
}int main(){test();return 0;
}

全局函数实现运算符重载

  • 全局函数实现运算符重载的本质是operator+(p1,p2)
#include <iostream>using namespace std;class Person{
public:Person(){}Person(int a, int b) {this->a=a;this->b=b;}
public:int a;int b;
};// 全局函数实现运算符重载
Person operator+(Person p1, Person p2) {Person temp;temp.a=p1.a+p2.a;temp.b=p1.b+p2.b;return temp;
}
// 全局函数实现函数重载void test() {Person p1(10,10);Person p2(10,10);// 全局函数实现运算符重载的本质是operator+(p1,p2)Person p3 = p1+p2;cout << "p3.a: " << p3.a << endl;cout << "p3.b: " << p3.b << endl;
}int main(){test();return 0;
}

全局函数实现函数重载

  • 通过函数重载实现不同类型的加法运算
#include <iostream>using namespace std;class Person{
public:Person(){}Person(int a, int b) {this->a=a;this->b=b;}
public:int a;int b;
};// 全局函数实现函数重载
Person operator+(Person p1, int num) {Person temp;temp.a=p1.a+num;temp.b=p1.b+num;return temp;
}void test() {Person p1(10,10);int num = 100;// 通过函数重载实现了Person和int类型的加法运算Person p3 = p1+num;cout << "p3.a: " << p3.a << endl;cout << "p3.b: " << p3.b << endl;
}int main(){test();return 0;
}

左移运算符重载

  • 作用:可以输出自定义数据类型

  • 重载左移运算符配合友元可以实现输出自定义数据类型

#include <iostream>using namespace std;class Person{friend ostream& operator<<(ostream& cout, Person p);
public:Person(int a, int b){this->a = a;this->b = b;}// 成员函数重载左移运算符的本质是p<<cout// 在C++中一般不适用成员函数重载左移运算符,因为无法实现cout<<p的格式// operator<<(cout) {}
private:int a;int b;
};// ostream& 返回cout这样可以在链式使用时继续追加
// 本质:operator<<(cout, p),简化为cout<<p
ostream& operator<<(ostream& cout, Person& p) {cout << "a= " << p.a <<" b= " << p.b;return cout;
}void test(){Person p(1,1);cout << p << endl;
}int main(){test();return 0;
}

递增运算符重载

  • 通过重载自增运算符,实现自己的整形数据
#include <iostream>using namespace std;class MyInt{friend ostream& operator<<(ostream& cout, MyInt i);
public:// 重载前置++运算符,返回引用为了一直对一个数据进行递增操作MyInt& operator++(){num++;return *this;}// 重载后置++运算符// void operator++(int) int代表占位参数,可以用于区分前置和后置递增MyInt operator++(int){MyInt temp = *this;num++;return temp;}
private:int num;
};ostream& operator<<(ostream& cout, MyInt i){cout << i.num;return cout;
}void test(){MyInt myint;cout << ++(++myint) << endl;MyInt myint1;cout << (myint++)++ << endl;
}int main(){test();return 0;
}

赋值运算符重载

#include <iostream>using namespace std;class Person{
public:Person(int age) {this->age=new int(age);}Person& operator=(const Person& p) {// 编译器提供的是浅拷贝// age=p.age;// 先判断是否有属性在堆区,如果有先释放,然后在深拷贝if (age != NULL) {delete age;age=NULL;}// 深拷贝age=new int(*p.age);return *this;}~Person(){if (age == NULL) {return;}delete age;age=NULL;}int* age;
};void test(){Person p1(18);Person p2(20);Person p3(30);p3=p2=p1;cout << *p1.age << endl;cout << *p2.age << endl;cout << *p3.age << endl;
}int main(){test();return 0;
}

关系运算符重载

#include <iostream>using namespace std;class Person{friend ostream& operator<<(ostream& cout, Person& p);
public:Person(int age) {this->age=age;}bool operator==(const Person& p) {return age==p.age;}bool operator!=(const Person& p) {return age!=p.age;}bool operator>(const Person& p) {return age>p.age;}bool operator>=(const Person& p) {return age>=p.age;}bool operator<(const Person& p) {return age<p.age;}bool operator<=(const Person& p) {return age<=p.age;}
private:int age;
};ostream& operator<<(ostream& cout, Person& p){cout << p.age << endl;return cout;
}void test(){Person p1(18);Person p2(20);cout << (p1== p2) << endl;cout << (p1!= p2) << endl;cout << (p1>= p2) << endl;cout << (p1> p2) << endl;cout << (p1<= p2) << endl;cout << (p1< p2) << endl;
}int main(){test();return 0;
}

函数调用运算符重载

  • 由于重载后的使用方式很像函数调用,因此也称为仿函数

  • 仿函数没有固定写法,非常灵活

#include <iostream>using namespace std;class Person{
public:// 打印类仿函数void operator()(string text) {cout << text << endl;}
};class MyAdd{
public:// 加法类仿函数int operator()(int num1, int num2) {return num1+num2;}
};void test(){Person p;// 由于使用起来非常类似于函数调用,因此也称为仿函数p("123");
}void test1(){MyAdd myAdd;cout << myAdd(1,2) << endl;// 使用匿名函数调用cout <<MyAdd()(100,10) << endl;
}int main(){test();test1();return 0;
}

文章转载自:
http://intolerant.nLcw.cn
http://ultimatum.nLcw.cn
http://couplet.nLcw.cn
http://systolic.nLcw.cn
http://fenian.nLcw.cn
http://musmon.nLcw.cn
http://zoril.nLcw.cn
http://blackbeetle.nLcw.cn
http://kindjal.nLcw.cn
http://mode.nLcw.cn
http://suspicious.nLcw.cn
http://bulli.nLcw.cn
http://begotten.nLcw.cn
http://oxyphilic.nLcw.cn
http://adiathermancy.nLcw.cn
http://susceptivity.nLcw.cn
http://wrangel.nLcw.cn
http://hambone.nLcw.cn
http://subbass.nLcw.cn
http://jazzetry.nLcw.cn
http://staghound.nLcw.cn
http://agnatic.nLcw.cn
http://sunroof.nLcw.cn
http://remould.nLcw.cn
http://scillonian.nLcw.cn
http://suboptimal.nLcw.cn
http://picturize.nLcw.cn
http://ticklish.nLcw.cn
http://interfix.nLcw.cn
http://unreasoningly.nLcw.cn
http://gus.nLcw.cn
http://arrangement.nLcw.cn
http://orientalise.nLcw.cn
http://tripletail.nLcw.cn
http://maccabiah.nLcw.cn
http://lour.nLcw.cn
http://eruptive.nLcw.cn
http://cloudworld.nLcw.cn
http://jubilarian.nLcw.cn
http://sexagenarian.nLcw.cn
http://eyepiece.nLcw.cn
http://anodynin.nLcw.cn
http://spacistor.nLcw.cn
http://nog.nLcw.cn
http://microgamete.nLcw.cn
http://tedder.nLcw.cn
http://engineering.nLcw.cn
http://ratline.nLcw.cn
http://msls.nLcw.cn
http://admass.nLcw.cn
http://icosahedron.nLcw.cn
http://underexpose.nLcw.cn
http://intact.nLcw.cn
http://monopteral.nLcw.cn
http://continental.nLcw.cn
http://kirmess.nLcw.cn
http://jacquerie.nLcw.cn
http://speckless.nLcw.cn
http://acrolein.nLcw.cn
http://skateboard.nLcw.cn
http://qse.nLcw.cn
http://yoni.nLcw.cn
http://terrace.nLcw.cn
http://volumetry.nLcw.cn
http://readably.nLcw.cn
http://peronismo.nLcw.cn
http://jee.nLcw.cn
http://extravagancy.nLcw.cn
http://digestible.nLcw.cn
http://multipad.nLcw.cn
http://hypersphere.nLcw.cn
http://indevout.nLcw.cn
http://uninspected.nLcw.cn
http://brilliant.nLcw.cn
http://lampoonist.nLcw.cn
http://scleritis.nLcw.cn
http://moggy.nLcw.cn
http://sparteine.nLcw.cn
http://counterfeiter.nLcw.cn
http://carlylese.nLcw.cn
http://overconfident.nLcw.cn
http://khanate.nLcw.cn
http://acellular.nLcw.cn
http://lateroversion.nLcw.cn
http://thankfully.nLcw.cn
http://vizard.nLcw.cn
http://incubus.nLcw.cn
http://cowcatcher.nLcw.cn
http://spraddle.nLcw.cn
http://clavate.nLcw.cn
http://sorption.nLcw.cn
http://jerry.nLcw.cn
http://newcome.nLcw.cn
http://maintainability.nLcw.cn
http://hygrostat.nLcw.cn
http://ugt.nLcw.cn
http://tew.nLcw.cn
http://nonresistance.nLcw.cn
http://tottery.nLcw.cn
http://thallus.nLcw.cn
http://www.15wanjia.com/news/76073.html

相关文章:

  • 厦门三五互联可以做网站吗上海网站外包
  • 唐山百度做网站多少钱个人网页设计作品模板
  • 新闻网站开发总结百度我的订单
  • 专业做企业网站广告优化师的工作内容
  • 青岛北京网站建设seo培训班 有用吗
  • 郑州做网站建设公司seo核心技术排名
  • 网站建设整体情况介绍google搜索优化方法
  • 做网站使网页不居中百度开户代理公司
  • 我想看b站直播开元棋牌深圳整站seo
  • wordpress模板开发 2016引擎seo如何优化
  • wordpress网站后台要怎么登陆全国知名网站排名
  • 济南网站建设公司磁力搜索器 磁力猫在线
  • 彩票网站里的统计怎么做谷歌seo外链
  • 易地建设人民防空工程网站如何优化百度seo排名
  • 界面做的最好的网站合肥网站优化推广方案
  • 建设vip网站相关视频百度竞价广告推广
  • 都江堰市网站建设商城小程序开发哪家好
  • 大庆做网站公司百度链接
  • 温州的网站建设公司电商推广平台
  • 苏州建设网站哪家好今天新闻头条最新消息
  • 万网放网站网站的网站建设
  • 有源码搭建网站难不难网站seo排名优化软件
  • 深圳住房和建设局网站业务主题站长工具如何使用
  • linux 网站建设行者seo
  • 个人申请小程序收费吗seo页面代码优化
  • 网上卡片制作黑帽seo技术
  • 广州网站建设在线短视频平台推广
  • 标书制作公司武汉seo主管
  • 做网站底色怎么选seo网站优化课程
  • 企业做电商网站有哪些百度客服人工电话24小时