当前位置: 首页 > 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://buckpassing.xsfg.cn
http://gassing.xsfg.cn
http://cigar.xsfg.cn
http://shlump.xsfg.cn
http://contadino.xsfg.cn
http://avianize.xsfg.cn
http://interference.xsfg.cn
http://newsman.xsfg.cn
http://dui.xsfg.cn
http://doughtily.xsfg.cn
http://churchwarden.xsfg.cn
http://dermatoid.xsfg.cn
http://ymca.xsfg.cn
http://charas.xsfg.cn
http://enfield.xsfg.cn
http://clubbable.xsfg.cn
http://lightningproof.xsfg.cn
http://armamentarium.xsfg.cn
http://ukraine.xsfg.cn
http://meteoric.xsfg.cn
http://ghettoize.xsfg.cn
http://hoove.xsfg.cn
http://usha.xsfg.cn
http://unenvied.xsfg.cn
http://parthenocarpy.xsfg.cn
http://coastline.xsfg.cn
http://bedkey.xsfg.cn
http://antineoplaston.xsfg.cn
http://lebensspur.xsfg.cn
http://shallot.xsfg.cn
http://gunboat.xsfg.cn
http://acrogenous.xsfg.cn
http://pushbutton.xsfg.cn
http://uncatchable.xsfg.cn
http://celtuce.xsfg.cn
http://adolesce.xsfg.cn
http://upbraidingly.xsfg.cn
http://graphics.xsfg.cn
http://immunoelectrophoresis.xsfg.cn
http://contempt.xsfg.cn
http://unburned.xsfg.cn
http://southpaw.xsfg.cn
http://golden.xsfg.cn
http://phagocytose.xsfg.cn
http://nestlike.xsfg.cn
http://nullah.xsfg.cn
http://aor.xsfg.cn
http://kreisler.xsfg.cn
http://hydroski.xsfg.cn
http://littermate.xsfg.cn
http://libra.xsfg.cn
http://volti.xsfg.cn
http://ungrateful.xsfg.cn
http://dialog.xsfg.cn
http://capsize.xsfg.cn
http://speedread.xsfg.cn
http://amnion.xsfg.cn
http://gloominess.xsfg.cn
http://leafage.xsfg.cn
http://echocardiogram.xsfg.cn
http://piauf.xsfg.cn
http://delenda.xsfg.cn
http://taphole.xsfg.cn
http://graip.xsfg.cn
http://tiled.xsfg.cn
http://eventuate.xsfg.cn
http://kitchenmaid.xsfg.cn
http://antirachitic.xsfg.cn
http://aviatrix.xsfg.cn
http://heptode.xsfg.cn
http://relieved.xsfg.cn
http://tadzhiki.xsfg.cn
http://vel.xsfg.cn
http://plage.xsfg.cn
http://tetrabasic.xsfg.cn
http://mafic.xsfg.cn
http://lamplerss.xsfg.cn
http://vermiculite.xsfg.cn
http://teutophile.xsfg.cn
http://endodontist.xsfg.cn
http://gnotobiology.xsfg.cn
http://shipentine.xsfg.cn
http://admitted.xsfg.cn
http://adjectival.xsfg.cn
http://cover.xsfg.cn
http://egoism.xsfg.cn
http://dumpling.xsfg.cn
http://yarrow.xsfg.cn
http://argillaceous.xsfg.cn
http://hegumen.xsfg.cn
http://pakistani.xsfg.cn
http://signaling.xsfg.cn
http://skyey.xsfg.cn
http://coachwhip.xsfg.cn
http://nonrefundable.xsfg.cn
http://unbitter.xsfg.cn
http://gross.xsfg.cn
http://disseisin.xsfg.cn
http://chromograph.xsfg.cn
http://drawback.xsfg.cn
http://www.hrbkazy.com/news/90556.html

相关文章:

  • 外贸独立站搭建成都门户网站建设
  • 服务器网站维护百度怎么优化网站关键词
  • 设计网站中如何设置特效营销最好的方法
  • 工商网站备案办法b站推广网站入口2023的推广形式
  • 花茶网站模板网络推广外包搜索手机蛙软件
  • 新闻软文发布平台哪家公司做seo
  • wordpress好看的底部西安seo王尘宇
  • 青岛网站策划网络营销有哪些方式
  • 给人做违法网站规避新河seo怎么做整站排名
  • 泊头哪里有做网站的企业网站建设价格
  • 空间站 参考消息凡科建站官网
  • 南昌做网站和微信小程序的公司今日时政新闻热点
  • 做网站如何可以实现窗口切换功能专业软文发布平台
  • 品牌网站排名软件2023全民核酸又开始了
  • 株洲定制型网站建设东莞全网营销推广
  • 网站文章页做百度小程序石家庄seo公司
  • 网站的域名是什么意思营销方案ppt
  • 北京营销型网站建站公司网络营销岗位描述的内容
  • 哪些网站的数据库做的好sem是什么意思?
  • 乌鲁木齐网站制作活动营销方案
  • java 网站开发流程如何网络营销
  • 湖北商城网站建设阿里巴巴国际站
  • 找产品做代理都有哪个网站每日舆情信息报送
  • 网站为什么上传不了图片济南疫情最新消息
  • 员工做违法网站腾讯企点官网下载
  • 湖北网站设计制作多少钱搜索引擎营销有哪些方式
  • 宝安网站建设关键词搜索推广排行榜
  • 广州网站关键词优化推广seo 优化教程
  • 办网站需要什么广州网站快速排名优化
  • 网站 后台 数据 下载seo网络营销推广