C++ why double pointer for out/return function parameter?

前端 未结 5 481
暗喜
暗喜 2020-12-09 03:37

I\'m relatively new to C++ and working on a fairly large C++ project at work. I notice handfuls of functions that take double pointers as parameters for objects that the fun

5条回答
  •  感情败类
    2020-12-09 04:25

    The short answer is that parameters in C++ are passed by value, so your function receives a copy of that pointer. Once you overwrite it inside your function, the change is lost.

    Your snippet however wants the change to be visible from the outside, so it needs a way to overwrite the actual pointer to the object, so it has to get a copy of a pointer to the pointer to the class, so it can overwrite the inner pointer and have it be visible from the outside.

提交回复
热议问题