Three questions about lifetime and scope.
From: Jason Heyes (jasonheyes_at_optusnet.com.au)
Date: 11/23/04
- Next message: Alf P. Steinbach: "Re: Keyword register"
- Previous message: Tom Widmer: "Re: MUCH simpler program displaying same behavior"
- Next in thread: Alf P. Steinbach: "Re: Three questions about lifetime and scope."
- Reply: Alf P. Steinbach: "Re: Three questions about lifetime and scope."
- Reply: Branimir Maksimovic: "Re: Three questions about lifetime and scope."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 23 Nov 2004 21:50:22 +1100
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.
- Next message: Alf P. Steinbach: "Re: Keyword register"
- Previous message: Tom Widmer: "Re: MUCH simpler program displaying same behavior"
- Next in thread: Alf P. Steinbach: "Re: Three questions about lifetime and scope."
- Reply: Alf P. Steinbach: "Re: Three questions about lifetime and scope."
- Reply: Branimir Maksimovic: "Re: Three questions about lifetime and scope."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|