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

前端 未结 5 488
暗喜
暗喜 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:29

    The canonical way to return an X is to pass a pointer to X. If X is a "pointer to MyClass", the canonical way to return it is to pass a "pointer to pointer to MyClass". You can't just pass a pointer to a MyClass to the function because the caller has no idea what the value of that pointer should be.

提交回复
热议问题