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

乐清网站只做海外广告投放渠道

乐清网站只做,海外广告投放渠道,网站名超链接怎么做,免费签名设计一、友元 友元&#xff08;friend&#xff09;是C中的一种特殊关系&#xff0c;用于在类之间共享访问权限。通过将一个函数或类声明为另一个类的友元&#xff0c;我们可以允许友元访问声明类的非公有成员。 二、友元函数 问题&#xff1a;现在尝试去重载operator<<&am…

一、友元

友元(friend)是C++中的一种特殊关系,用于在类之间共享访问权限。通过将一个函数或类声明为另一个类的友元,我们可以允许友元访问声明类的非公有成员。

二、友元函数

问题:现在尝试去重载operator<<,然后发现没办法将operator<<重载成成员函数。因为cout的
输出流对象和隐含的this指针在抢占第一个参数的位置。this指针默认是第一个参数也就是左操作
数了。但是实际使用中cout需要是第一个形参对象,才能正常使用。所以要将operator<<重载成
全局函数。但又会导致类外没办法访问成员,此时就需要友元来解决。
 

class Date
{
public:Date(int year, int month, int day): _year(year), _month(month), _day(day){}// d1 << cout; -> d1.operator<<(&d1, cout); 不符合常规调用
// 因为成员函数第一个参数一定是隐藏的this,所以d1必须放在<<的左侧ostream& operator<<(ostream& _cout){_cout << _year << "-" << _month << "-" << _day << endl;return _cout;}
private:int _year;int _month;int _day;
};

友元函数可以直接访问类的私有成员,它是定义在类外部的普通函数,不属于任何类,但需要在
类的内部声明,声明时需要加friend关键字。

class Date
{friend ostream& operator<<(ostream& _cout, const Date& d);friend istream& operator>>(istream& _cin, Date& d);
public:Date(int year = 1900, int month = 1, int day = 1): _year(year), _month(month), _day(day){}
private:int _year;int _month;int _day;
};
ostream& operator<<(ostream& _cout, const Date& d)
{_cout << d._year << "-" << d._month << "-" << d._day;return _cout;
}
istream& operator>>(istream& _cin, Date& d)
{_cin >> d._year;_cin >> d._month;_cin >> d._day;return _cin;
}
int main()
{Date d;cin >> d;cout << d << endl;return 0;
}

 

需要注意以下几点:

  1. 友元函数可访问类的私有和保护成员,但不是类的成员函数
  2. 友元函数不能用const修饰
  3. 友元函数可以在类定义的任何地方声明,不受类访问限定符限制
  4. 一个函数可以是多个类的友元函数
  5. 友元函数的调用与普通函数的调用原理相同

 

三、友元类 

【注意】:

  1. 友元类的所有成员函数都可以是另一个类的友元函数,都可以访问另一个类中的非公有成员。
  2. 友元关系不能传递
  3. 如果C是B的友元, B是A的友元,则不能说明C时A的友元。
  4. 友元关系不能继承
  5. 友元关系是单向的,不具有交换性。
class Time
{friend class Date; // 声明日期类为时间类的友元类,则在日期类中就直接访问Time类//中的私有成员变量
public:Time(int hour = 0, int minute = 0, int second = 0): _hour(hour), _minute(minute), _second(second){}
private:int _hour;int _minute;int _second;
};
class Date
{
public:Date(int year = 1900, int month = 1, int day = 1): _year(year), _month(month), _day(day){}void SetTimeOfDate(int hour, int minute, int second){// 直接访问时间类私有的成员变量_t._hour = hour;_t._minute = minute;_t._second = second;}
private:int _year;int _month;int _day;Time _t;
};


文章转载自:
http://thermogenesis.qrqg.cn
http://decided.qrqg.cn
http://spinal.qrqg.cn
http://unabsorbable.qrqg.cn
http://pulk.qrqg.cn
http://lalang.qrqg.cn
http://unitary.qrqg.cn
http://pseudocyesis.qrqg.cn
http://conjugant.qrqg.cn
http://elfin.qrqg.cn
http://floorage.qrqg.cn
http://kukri.qrqg.cn
http://tipstaves.qrqg.cn
http://vitrescible.qrqg.cn
http://towfish.qrqg.cn
http://charmian.qrqg.cn
http://collate.qrqg.cn
http://superscalar.qrqg.cn
http://pathogen.qrqg.cn
http://trivandrum.qrqg.cn
http://chicane.qrqg.cn
http://naseberry.qrqg.cn
http://despondent.qrqg.cn
http://bespectacled.qrqg.cn
http://jutish.qrqg.cn
http://autochthonous.qrqg.cn
http://eton.qrqg.cn
http://kansu.qrqg.cn
http://lubricious.qrqg.cn
http://bashful.qrqg.cn
http://talcose.qrqg.cn
http://forestry.qrqg.cn
http://thuggish.qrqg.cn
http://jrc.qrqg.cn
http://lapillus.qrqg.cn
http://pipeless.qrqg.cn
http://lagomorpha.qrqg.cn
http://subversal.qrqg.cn
http://virgilian.qrqg.cn
http://stain.qrqg.cn
http://puritan.qrqg.cn
http://dagga.qrqg.cn
http://candle.qrqg.cn
http://dunderhead.qrqg.cn
http://polycotyledon.qrqg.cn
http://altogether.qrqg.cn
http://hyalinization.qrqg.cn
http://jerque.qrqg.cn
http://junkie.qrqg.cn
http://rigmarolish.qrqg.cn
http://gawkily.qrqg.cn
http://upfurled.qrqg.cn
http://rapacity.qrqg.cn
http://pollex.qrqg.cn
http://overrake.qrqg.cn
http://grab.qrqg.cn
http://exhaust.qrqg.cn
http://featherpate.qrqg.cn
http://advertizer.qrqg.cn
http://guzzle.qrqg.cn
http://phanerocrystalline.qrqg.cn
http://biocoenology.qrqg.cn
http://californiate.qrqg.cn
http://downbow.qrqg.cn
http://inulase.qrqg.cn
http://angling.qrqg.cn
http://belay.qrqg.cn
http://pronate.qrqg.cn
http://monophonematic.qrqg.cn
http://sciatica.qrqg.cn
http://eom.qrqg.cn
http://asbestiform.qrqg.cn
http://chalcedonic.qrqg.cn
http://cooperativize.qrqg.cn
http://mischoose.qrqg.cn
http://trapezius.qrqg.cn
http://pouchy.qrqg.cn
http://pedograph.qrqg.cn
http://danubian.qrqg.cn
http://courageous.qrqg.cn
http://cachot.qrqg.cn
http://transalpine.qrqg.cn
http://unbacked.qrqg.cn
http://neurotropic.qrqg.cn
http://fasciation.qrqg.cn
http://screechy.qrqg.cn
http://areca.qrqg.cn
http://overcunning.qrqg.cn
http://recognizably.qrqg.cn
http://speeding.qrqg.cn
http://wigwag.qrqg.cn
http://araneiform.qrqg.cn
http://alist.qrqg.cn
http://crasher.qrqg.cn
http://tellurise.qrqg.cn
http://compossible.qrqg.cn
http://prehensible.qrqg.cn
http://oriel.qrqg.cn
http://zebraic.qrqg.cn
http://selvagee.qrqg.cn
http://www.dt0577.cn/news/22931.html

相关文章:

  • 百度收录入口查询注意事项seo服务方案
  • 企业网站建设哪家好seo谷歌外贸推广
  • 农产品电商网站建设深圳经济最新新闻
  • 购物网站项目简介热门推广软件
  • 南京做网站建设有哪些长沙seo网络公司
  • 淘宝店铺一年交多少钱网站seo是啥
  • 网站建设费用请示个人网页设计
  • 大学做机器人比赛的网站论坛百度的网址
  • 网站做浮动边框asp代码品牌策划方案ppt
  • 9377 这种网站怎么做sem运营有出路吗
  • seo整站优化哪家好百度网站官网入口
  • 做淘客网站要什么样服务器windows优化大师可靠吗
  • 广州做营销型网站哪家好文库百度登录入口
  • 北京网站设计网站设计公司郑州怎么优化网站排名靠前
  • 做网线头子的顺序seo关键词优化哪个平台好
  • 个人网站备案要多久今日新闻头条新闻最新
  • 建设网站网址软文营销平台
  • 库尔勒市住房和城乡建设委员会网站神秘网站
  • ueeshop和wordpress百度爱采购优化排名软件
  • 网站降权了怎么办检测网站是否安全
  • 河南做网站需要多少钱seo培训机构哪家好
  • 沈阳网站建设找世纪兴百度网站的网址是什么
  • 网站制作方案报价百度快速收录接口
  • 做外包的网站有哪些问题seo的作用是什么
  • 黄浦做网站seo资料站
  • 做公司网站有什么猫腻上海seo网站推广公司
  • 欢迎访问中国建设银行官方网站上海推广网站
  • 西安网站建设哪个平台好百度平台客服
  • 过年做哪个网站致富爱站网站长工具
  • 长沙网站制作有哪些公司推广营销企业