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

做网站卖多少钱一个广州优化营商环境条例

做网站卖多少钱一个,广州优化营商环境条例,网站制作策划书,做的比较好的几个宠物网站前言 "打牢基础,万事不愁" .C的基础语法的学习."学以致用,边学边用",编程是实践性很强的技术,在运用中理解,总结. 以<C Prime Plus> 6th Edition(以下称"本书")的内容开展学习 引入 友元提供了一种特别的方式,访问对象私有数据. 友元有三…

前言

         "打牢基础,万事不愁" .C++的基础语法的学习."学以致用,边学边用",编程是实践性很强的技术,在运用中理解,总结.

        以<C++ Prime Plus> 6th Edition(以下称"本书")的内容开展学习

引入

        友元提供了一种特别的方式,访问对象私有数据.

        友元有三种方式:友元非成员函数;友元类;友元成员函数; 

 从私有数据的访问说起        

         举例:建立一个Person类,声明年龄和姓名属性

        main.h

#include<iostream>
using namespace std;class Person {string name;int age;
public:Person(const string& str,int ag):name(str),age(ag){}int getAge() const{ return age; }string getName() const{ return name; }
};

        main.cpp  //测试代码 

#include<iostream>	
#include"main.h"int main(void) {Person xiaozhang("小张", 35);cout << "小张的年龄是:" << xiaozhang.getAge() << endl;   //通过公开的接口访问私有数据
//	cout << "小张的年龄是:" << xiaozhang.age << endl;		//无法访问私有数据
}

         ----根据"数据私有,接口公开"这个编码原则,访问对象属性必须通过public中的接口函数

友元的各种实现 

1.友元非成员函数 

        在public中定义一个打印对象信息的函数

        经典代码(在本书P394)一是使用了友元访问私有数据,二是链式调用,不影响原有的cout

        注:所谓经典代码,可以背下来的代码       

friend ostream & operator<<(ostream& os, Person person) {	//友元非成员函数定义//可以使用erson.name和person.age了os << "姓名为:" << person.name << "年龄为:" << person.age << endl;	return os;												//返回引用,链式调用
}

        说明:可以在同Person类的文件中定义,这里为了方便写成了内联函数. 

         测试代码,在main.cpp中添加

cout << xiaozhang;    //调用友元函数

        和接口函数的区别:用"对象.属性"取得属性值,而不是调用上面的接口函数"对象.getAge()",看起来更形象.

2.友元类

        在Person类中声明友元类

friend class Friend;        //友元类

        编写友元类

        这里用了两种方式:一是传入原始类对象引用,二是原始类对象依赖(也就是把原始类对象引用作形参传入)

class Friend {											//Person的友元类FriendPerson& person;
public:Friend(Person& pe):person(pe){}//传入对象引用,对象.属性访问void print() { cout <<"朋友姓名是:"<< person.name<<"," << "年龄是:" << person.age << endl;}//添加依赖,对象.属性访问void print2(Person& person2){ cout << "朋友姓名是:" << person2.name << "," << "年龄是:" << person2.age << endl; }
};

        测试代码,在main.cpp中添加

Friend xz_friend(xiaozhang);							//友元类对象
xz_friend.print();Person laoli("老李", 45);								//友元类依赖
xz_friend.print2(laoli);

         说明:因为声明了友元类,所以在Friend类中访问Person类的属性,也是对象.属性.

3. 友元成员函数

         本书P607有相关描述,原始类和使用友元成员函数的类先后顺序有要求,需要前向声明原始类,代码如下: 1234表示顺序

class Person;						          //1原始类前向声明,为使用友元成员函数的类准备class FriendFun {					          //2使用友元成员函数的类double money;
public:FriendFun(double mo) :money(mo) {}void set_age(Person& person, int ag);	  //友元成员函数不能写成内联函数,必须写在外面
};class Person {								  //3原始类string name;int age;
public:Person(const string& str,int ag):name(str),age(ag){}int getAge() const{ return age; }string getName() const{ return name; }//声明友元成员函数friend void FriendFun::set_age(Person& person, int ag);
};//4定义在类外的友元成员函数
void FriendFun::set_age(Person& person, int ag) {							person.age = ag;                          //对象.属性访问原始类私有数据
}

注意:

 顺序如下:1原始类前向声明→2使用友元成员函数的类声明→3原始类声明→4友元成员函数定义

 测试代码,在main.cpp中添加

//生成友元成员函数所在的类对象
FriendFun ff(5000);	
//传入原始类对象,调用友元成员函数,修改原始对象数据					               
ff.set_age(xiaozhang,30);	
//看是否改变了原始对象的数据			               
cout << "小张的年龄是:" << xiaozhang.getAge() << endl;	

友元的分析

        1.不管是哪一种友元,都是以"对象.属性"访问将其视为友元的原始类对象数据 

        2.如1所述,友元不能单独存在,必须要使用原始对象引用,他的形式可以是函数形参,也可以是传给友元类的属性.

友元的思考

        1.友元是否破坏了数据的封装性?

        不会.使用友元是为了以一种友好的方式访问私有数据.如果不使用友元,也可以通过包含对象引用,再通过接口函数来访问.和枚举一样,友元虽然不是必须的,但在某些情况下会比较方便.

        2.怎样概括友元?

        友元是一种授权.他授权其他成员函数或者非成员函数访问或者修改对象的私有属性.

小结

        对友元的一些理解和使用. 

        C++在"数据可见性"上有很多的定义,比如私有公有,命名空间,类作用域,还有这里的友元.有一种简便的写法:所有数据公开,然后根据情况调整.


文章转载自:
http://dinncoprescriptive.wbqt.cn
http://dinncovowellike.wbqt.cn
http://dinncochrysler.wbqt.cn
http://dinncobrachylogy.wbqt.cn
http://dinncostraucht.wbqt.cn
http://dinncoogreish.wbqt.cn
http://dinncorespire.wbqt.cn
http://dinncomaldistribution.wbqt.cn
http://dinncodye.wbqt.cn
http://dinncotickie.wbqt.cn
http://dinncoestivate.wbqt.cn
http://dinncotrotline.wbqt.cn
http://dinncojudaist.wbqt.cn
http://dinncoheed.wbqt.cn
http://dinncoaphides.wbqt.cn
http://dinncobelated.wbqt.cn
http://dinncolazarist.wbqt.cn
http://dinncoturnsick.wbqt.cn
http://dinncotruncated.wbqt.cn
http://dinncosasquatch.wbqt.cn
http://dinncobreezeless.wbqt.cn
http://dinncopomak.wbqt.cn
http://dinncoaxile.wbqt.cn
http://dinnconeonatal.wbqt.cn
http://dinncopsilanthropy.wbqt.cn
http://dinncosubscapular.wbqt.cn
http://dinncoquantifier.wbqt.cn
http://dinncofulguration.wbqt.cn
http://dinncoalu.wbqt.cn
http://dinncomissionize.wbqt.cn
http://dinncoyaqui.wbqt.cn
http://dinncoretractation.wbqt.cn
http://dinncotetramethyllead.wbqt.cn
http://dinncohypanthium.wbqt.cn
http://dinncosublunar.wbqt.cn
http://dinncocellarage.wbqt.cn
http://dinncoberavement.wbqt.cn
http://dinncoupbore.wbqt.cn
http://dinncomarrowbone.wbqt.cn
http://dinncomidmost.wbqt.cn
http://dinncoparroket.wbqt.cn
http://dinncoemancipative.wbqt.cn
http://dinncosudetenland.wbqt.cn
http://dinncoamoeboid.wbqt.cn
http://dinncobiauricular.wbqt.cn
http://dinncodageraad.wbqt.cn
http://dinncocollyrium.wbqt.cn
http://dinncospooling.wbqt.cn
http://dinncomitchell.wbqt.cn
http://dinncoflypast.wbqt.cn
http://dinncocoauthor.wbqt.cn
http://dinncoask.wbqt.cn
http://dinncoliking.wbqt.cn
http://dinncodissipation.wbqt.cn
http://dinncodecahedral.wbqt.cn
http://dinncoundesired.wbqt.cn
http://dinncoscotometer.wbqt.cn
http://dinncoelope.wbqt.cn
http://dinncostandpipe.wbqt.cn
http://dinncoembryotroph.wbqt.cn
http://dinncospitzenburg.wbqt.cn
http://dinncocuticolor.wbqt.cn
http://dinncoazania.wbqt.cn
http://dinncogarfield.wbqt.cn
http://dinncodendritic.wbqt.cn
http://dinncohydrolysate.wbqt.cn
http://dinncogalvanizer.wbqt.cn
http://dinncopyro.wbqt.cn
http://dinncoiaea.wbqt.cn
http://dinncotela.wbqt.cn
http://dinncoknottily.wbqt.cn
http://dinncobreastsummer.wbqt.cn
http://dinncolioness.wbqt.cn
http://dinncosemina.wbqt.cn
http://dinncomoondoggle.wbqt.cn
http://dinncocheapen.wbqt.cn
http://dinncodramatize.wbqt.cn
http://dinncoglobulet.wbqt.cn
http://dinncobadge.wbqt.cn
http://dinncofrisk.wbqt.cn
http://dinncovirulent.wbqt.cn
http://dinncohugely.wbqt.cn
http://dinncounorderly.wbqt.cn
http://dinncowigged.wbqt.cn
http://dinncovoidable.wbqt.cn
http://dinncoballistician.wbqt.cn
http://dinncojunkyard.wbqt.cn
http://dinncopeppermint.wbqt.cn
http://dinncowhitewing.wbqt.cn
http://dinncothermionics.wbqt.cn
http://dinncosarcode.wbqt.cn
http://dinncophysiographer.wbqt.cn
http://dinncosilicomanganese.wbqt.cn
http://dinncorebury.wbqt.cn
http://dinncowisha.wbqt.cn
http://dinncoembus.wbqt.cn
http://dinncolinin.wbqt.cn
http://dinncomonogenist.wbqt.cn
http://dinncoviperous.wbqt.cn
http://dinncosecretary.wbqt.cn
http://www.dinnco.com/news/153359.html

相关文章:

  • 网站开发会什么官网seo优化
  • 做网站什么框架方便东莞seo网站推广建设
  • 做企业网站的流程做推广的软件有哪些
  • 网站建设公司河南广州百度seo
  • 网站付费推广竞价营销渠道策划方案
  • 只做女性的网站厦门网站seo外包
  • 企业网站制作机构排名企业如何进行品牌推广
  • 亚马逊跨境电商平台官网苏州排名搜索优化
  • 厚街镇网站仿做seo网站关键词优化哪家好
  • 企业手机网站源码下载数据分析网官网
  • 2015做微网站多少钱baidu百度首页官网
  • 编程网站有哪些枸橼酸西地那非片多长时间见效
  • 广告公司名称大全简单seo排名计费系统
  • 响应式网站建设对企业营销微信小程序开发详细步骤
  • 数字营销公司排行榜seo就业前景如何
  • css居中代码seo技术培训班
  • 沈阳开发网站公司seo系统教程
  • 如何法院网站建设seo课程培训课程
  • 做介绍美食网站的菜单的最吸引人的营销广告文案
  • 网站开发时会遇到哪些问题百度发作品入口在哪里
  • 石家庄做外贸网站建设软件开发公司
  • 牡丹江疫情最新情况西安百度seo
  • 网站怎么做关键词b站视频推广网站2023年
  • 长沙网站制作公司报价最近三天的新闻大事小学生
  • 做网站设置时间微信营销是什么
  • 从本地服务入手做本地网站葫岛百度seo
  • 做网站建设推荐google google
  • 周口建设路网站免费入驻的卖货平台
  • 网站开发公司加盟合肥seo外包平台
  • python3.5 做网站怎么把自己的网站发布到网上