关于生命和范围的三个问题。 [英] Three questions about lifetime and scope.

查看:54
本文介绍了关于生命和范围的三个问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这个原型的功能:


void foo(条形条);


1.程序可以调用foo并允许只有一个可寻址的Bar对象存在

一次?

现在考虑以下程序:


class Bar

{

int value;

public:

Bar():value(0){}

void change(int new_value){value = new_value; }

};


void foo(酒吧){}


int main()

{

酒吧;

bar.change(1);

foo(bar);

返回0;

}


2.可以修改此程序而无需更改为foo和Bar,以便:

i)主要调用具有相同bar值的foo,并且

ii)一次只存在一个可寻址的Bar对象。

3.什么是前两个问题的实际意义(如果有的话)

与数据共享和写时复制有关吗?

请通过示例支持您的答案。感谢任何帮助。

Consider the function with this prototype:

void foo(Bar bar);

1. Can a program call foo and allow only one addressable Bar object to exist
at a time?
Now consider the following program:

class Bar
{
int value;
public:
Bar() : value(0) { }
void change(int new_value) { value = new_value; }
};

void foo(Bar bar) { }

int main()
{
Bar bar;
bar.change(1);
foo(bar);
return 0;
}

2. Can this program be modified without change to foo and Bar so that:

i) main calls foo with the same value of bar, and
ii) only one addressable Bar object exists at a time.
3. What is the practical significance, if any, of the previous two questions
in relation to data sharing and copy-on-write?
Please support your answers with examples. Any help is appreciated.

推荐答案

* Jason Heyes:
* Jason Heyes:
[作业问题]




偏离主题;请参阅关于家庭作业问题的常见问题解答。


-

答:因为它弄乱了人们通常阅读文本的顺序。

问:为什么这么糟糕?

A:热门发布。

问:usenet和电子邮件中最烦人的事情是什么?



Off-topic; see the FAQ on HOMEWORK QUESTIONS.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


" Alf P. Steinbach" <人*** @ start.no>在消息中写道

新闻:41 ***************** @ news.individual.net ...
"Alf P. Steinbach" <al***@start.no> wrote in message
news:41*****************@news.individual.net...
*杰森Heyes:
[作业问题]



非主题;请参阅关于家庭作业问题的常见问题解答。

- 答:A:因为它弄乱了人们通常阅读文本的顺序。
问:为什么这么糟糕?
答:热门帖子。
问:usenet和电子邮件中最烦人的事情是什么?



Off-topic; see the FAQ on HOMEWORK QUESTIONS.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?




如何修改我的帖子让论坛没有把它解释为作业?



How do I modify my post so that the forum doesn''t interpret it as homework?


* Jason Heyes:
* Jason Heyes:
[引用签名]


不要引用签名;纠正;请参阅有关如何发布的常见问题解答。

* Jason Heyes:* Alf P. Steinbach:
[quoting signature]
Do not quote signatures; corrected; see FAQs on how to post.
* Jason Heyes: * Alf P. Steinbach:
* Jason Heyes:
* Jason Heyes:
[作业问题]



非主题;请参阅有关家庭作业问题的常见问题解答。



Off-topic; see the FAQ on HOMEWORK QUESTIONS.



如何修改我的帖子,以便论坛不会将其解释为作业?



How do I modify my post so that the forum doesn''t interpret it as homework?




你不能。


问题


3.以前有什么实际意义关于数据共享和写时复制的两个问题?


证据太强了。


-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门发布。

问:usenet和电子邮件中最烦人的事情是什么?



You can''t.

The question

3. What is the practical significance, if any, of the previous two
questions in relation to data sharing and copy-on-write?

is too strong evidence.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


这篇关于关于生命和范围的三个问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆