Paul McCarthy
Paul McCarthy

Reputation: 890

Any idea why ** is used in this case

Any idea why ** is used in this case?

HRESULT CreateSolidColorBrush(
  const D2D1_COLOR_F & color,
  ID2D1SolidColorBrush** solidColorBrush
);

The above is from Microsoft documentation https://learn.microsoft.com/en-us/windows/win32/api/d2d1/nf-d2d1-id2d1rendertarget-createsolidcolorbrush(constd2d1_color_f__id2d1solidcolorbrush)

What is the benefit of using a pointer to a pointer in this case?

(Why didn't they develop the function that just returned ID2D1SolidColorBrush*)

Upvotes: 0

Views: 118

Answers (1)

Jean-Baptiste Yunès
Jean-Baptiste Yunès

Reputation: 36441

1. What is the benefit of using a pointer to a pointer in this case?

Because that function is probably intented to modify a pointer you may pass giving its address.

When this method returns, contains the address of a pointer to the new brush. This parameter is passed uninitialized.

It may have been declared as reference to pointer, but it is more clear to user that he must give the address of the pointer to be modified, as it will enforce him the semantic.

2. Why didn't they develop the function that just returned ID2D1SolidColorBrush*?

Because the function already returns something that is a status.

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Separating status and computed value is a good practice.

Upvotes: 2

Related Questions