ssercpp12 / Homework

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

HW4 #12

Open YouseYeung opened 11 years ago

YouseYeung commented 11 years ago

// Gets the Value at the given index. Modifies |out_value| (and returns true) // only if the index falls within the current list range. // Note that the list always owns the Value passed out via |out_value|. bool ListValue:: Get(size_t index, const Value\ out_value) const;

师兄师兄~这个函数的功能是用list_[index]的内容来修改out_value的内容吗? 是的话,这里为什么有 /const Value* out_value*/ const限定哦

ssercpp12 commented 11 years ago

const Value** out_value is a (non-const) pointer to a (non-const) pointer to a const Value. So you can use *out_value = list_[index];.

Here is an example to help you understand.

int main() {
  int a = 10;
  const int* ptr = &a;  // You can't used | *ptr = 100 |.
  const int** p_ptr = &ptr;  // You can't used | *(*p_ptr) = 1000; |.

  const int* ptr_2 = &a;
  *p_ptr = ptr_2;  // Here you can change the *p_ptr to ptr_2;

  return 0;
}
YouseYeung commented 11 years ago

原来是酱紫!不过把地址值传过去的话,删除指针的时候不会出现问题吗?