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

linux安装wordpress江苏seo哪家好

linux安装wordpress,江苏seo哪家好,烟台seo推广优化,公司网站内容的更新友元 意义 程序中,有些私有属性也想让类外特殊的一些函数或者类进行访问,就要用到友元技术 关键字 friend 友元的三种实现 全局函数做友元 class Room{friend void test(Person &p);//friend class test;public:string phone_number;private:string…

友元

  • 意义
    • 程序中,有些私有属性也想让类外特殊的一些函数或者类进行访问,就要用到友元技术
  • 关键字
    • friend
  • 友元的三种实现
    • 全局函数做友元
    class Room{friend void test(Person &p);//friend class test;public:string phone_number;private:string bedroom;
    }void test(Person &p){cout << p->bedroom << endl;}
    
    • 类做友元
      • friend class test;
    • 成员函数做友元
      • friend void GoodGay::visit();
      • GoodGay类下的visit成员函数作为本类的好朋友可以访问私有成员

运算符重载

  • 概念
    • 对已有的运算符重新进行定义,赋予其另一种功能,以适应不同的数据类型
    • 主要是重载函数的函数名就是operator,这是编译器起好的
  • 加号
    • 成员函数重载
    • 调用的本质Person p3 = p1.operator+(p2);
      class Person{public:Person operator+(Person &p){Person temp;temp.m_A = this->m_A + p.m_A;temp.m_B = this->m_B + p.m_Areturn temp;}}
    
    • 全局函数重载
    • 调用的本质Person p3 = operator+(p1, p2);
      Person operator+(Person &p1, Person &p2){Person temp;temp.m_A = p1.m_A + p2.m_A;temp.m_B = p1.m_B + p2.m_B;return temp;}
    
    • 函数重载依然适用于符号重载
  • 左移—输出—可以输出自定义数据类型—需要配合友元
    • 成员函数—不可行—因为无法实现对象在右边这种情况
      • p.operator<<(cout)简化为p << cout
    • 只能利用全局函数重载
      • operator<<(cout, p) 简化 cout << p
      ostream& operator<<(ostream& cout, Person &p){cout << "m_A = " << p.m_A;return cout;}//cout其实也是一个对象,为了满足链式编程,故而不可以重新创建后返回因此采用引用
    
    • 问题—如果是私有属性,这种全局函数无法访问怎么办—友元函数
  • 递增/递减运算符重载—存在前置递增和后置递增
    • 前置递增和后置递增的区分—采用占位参数
    • 前置递增返回的是引用,后置递增返回的是数值
      • 因为后置递增返回的是临时对象
      class Num{friend ostream& operator<<(ostream& cout, Num n);private:int n_Num;public:Num(int a): n_Num(a) {return ;}Num& operator++(void){n_Num++;return *this;}Num operator++(int){Num temp = (n_Num);n_Num++;return temp;}   };ostream& operator<<(ostream& cout, Num& n){cout << n.n_Num << endl;return cout;}int main(){Num n(1);cout << n++ <<endl;cout << n << endl;cout << ++n << endl;return 0;}
    
  • 赋值运算符
    • 赋值运算=其实也是默认就有的—属性值拷贝
    • 编译器提供的赋值运算符的操作是一个浅拷贝的操作,因此在涉及到内存问题时候需要进行深拷贝,故而需要进行重载
    • = 有连续赋值行,因此,涉及到链式编程
      class Age{friend ostream& operator<<(ostream& cout, Age& n);private:int* m_age;public:Age(int age){m_age = new int(age);}Age(const Age& age){if(m_age != NULL){delete m_age;m_age = NULL;}m_age = new int(*age.m_age);}Age& operator=(Age &p){if(m_age != NULL){delete m_age;m_age = NULL;}m_age = new int(*p.m_age);return *this;}~Age(){if(m_age != NULL){delete m_age;m_age = NULL;}}};ostream& operator<<(ostream& cout, Age& n){cout << *n.m_age << endl;return cout;}int main(){Age a(10);Age b(20);Age c(30);cout << a << endl;cout << b << endl;cout << c << endl;a = b = c;cout << a << endl;return 0;}
    
  • 关系运算符
    • 意义
      • 让两个对象可以进行比较
      class Person{public:int m_age;string m_name;Person(string m_name, int m_age){this->m_name = m_name;this->m_age = m_age;}bool operator==(Person& p){if(this->m_age == p.m_age && this->m_name == p.m_name){return true;}return false;}bool operator!=(Person& p){if(this->m_age != p.m_age || this->m_name == p.m_name){return true;}return false;}};
    
  • 函数调用运算
    • ()也可以重载
    • 由于重载后使用的方式非常像函数的调用,因此称为访函数
    • 访函数没有固定写法,非常灵活
      class Myprintf{public:void operator()(string test){cout << test << endl;}}Myprintf printf;printf("hello cpp");
    
  • 匿名函数
    • 类型()
    • Myprintf()(“hello cpp”);
http://www.yayakq.cn/news/859826/

相关文章:

  • 信息管理网站开发实验报告站群wordpress
  • aspcms网站无法打开网站开发通常叫什么部门
  • 模板建站有什么不好?做好档案整理及网站建设
  • 做一个公司网站一般需要多少钱色彩搭配 网站
  • 杭州网络公司项目合作怎样优化网站排名
  • windows优化大师的功能seo网页推广
  • 快要到期的域名网站网络营销是网上销售吗
  • 嘉兴做微网站做网站要的图片斗鱼
  • 商业网站开发实训心得体会范文wordpress x站
  • 网站页脚内容济南城市建设职业学院官网招生网
  • 怎么用织梦搭建网站淄博网站排名公司
  • 德清县建设银行官方网站网站地市频道建设
  • 网站备案都需要什么张店网站推广
  • 东莞工信部网站怎么做像滴滴一样网站
  • 北京建网站公司哪家便宜企业vi设计的基本要素
  • 西安知名网站制作公司网络运维需要懂什么技术
  • 密云建设网站全自动在线网页制作
  • 营销优化型网站怎么做域名到期了网站会打不开吗
  • 试述网站建设的步骤过程南昌网站建设方案外包
  • 网站开发客户来源网站建设华网天下公司
  • php网站开发教程网络优化首先要有网站
  • 网站建设用什么软件国外用的网站
  • 深圳网站建设啊中国建站公司
  • asp大型网站开发杭州网站如何制作
  • 化妆网站模板下载免费wordpress 文章添加附件
  • 创建网站需要哪些步骤电商网站零售客户
  • 全屋定制十大名牌口碑深圳seo优化公司搜索引擎优化方案
  • 网站seo关键字优化如何刷关键词指数
  • 网站开发结构文档电子商务网站开发开发背景
  • 北京海淀房管局网站钦州建设局网站