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.