为了账号安全,请及时绑定邮箱和手机立即绑定

函数返回引用怎么理解,sysop函数返回的引用是谁的引用?looper的还是sysopyer的?

函数返回引用怎么理解,sysop函数返回的引用是谁的引用?looper的还是sysopyer的?

C++
符号看象限CC 2017-03-30 10:17:12
// strtref.cpp -- using structure references#include <iostream>using namespace std;struct sysop{    char name[26];    char quote[64];    int used;};const sysop & use(sysop & sysopref);  // function with a reference return typeint main(){// NOTE: some implementations require using the keyword static// in the two structure declarations to enable initialization    sysop looper =    {        "Rick \"Fortran\" Looper",        "I'm a goto kind of guy.",        0    };    use(looper) ;            // looper is type sysop    cout << "Looper: " << looper.used << " use(s)\n";    sysop copycat; copycat = use(looper);    cout << "Looper: " << looper.used << " use(s)\n";    cout << "Copycat: " << copycat.used << " use(s)\n";    cout << "use(looper): " << use(looper).used << " use(s)\n";    return 0;}// use() returns the reference passed to itconst sysop & use(sysop & sysopref){    cout << sysopref.name << " says:\n";    cout << sysopref.quote << endl;    sysopref.used++;    return sysopref;}
查看完整描述

1 回答

?
浅_忆

TA贡献2条经验 获得超0个赞

不好意思,不会C++
查看完整回答
反对 回复 2017-04-01
  • 1 回答
  • 1 关注
  • 1001 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信