ssercpp12 / Homework

Homework result for 12 sser cpp
1 stars 8 forks source link

Should 'Set()' and 'Get()' do deep copy? #14

Open oath-jia opened 11 years ago

oath-jia commented 11 years ago

Should 'Set()' and 'Get()' do deep copy?

ssercpp12 commented 11 years ago

You don't need deep copy. Because once you pass a pointer to ListValue, it should manage it.

ListValue list;
list.Set(0, new FundamentalValue(true));
oath-jia commented 11 years ago

But we can also change the content that any pointer points by other way, without functions of ListValue.

ListValue list;
list.Set(0, new FundamentalValue(true));
Value* v;
list.Get(0, &v);
delete v;

Is this not a bug?

ssercpp12 commented 11 years ago

From user's(who use the ListValue) point of view, he shouldn't delete the v because this pointer is managed by ListValue.

oath-jia commented 11 years ago

I see. Thank you~