Advertisement

Optional arguments confusion

Started by July 21, 2017 05:37 AM
5 comments, last by Kylotan 7 years, 4 months ago

I am watching at this page -> https://msdn.microsoft.com/en-us/library/windows/desktop/dd371301(v=vs.85).aspx


HRESULT CreateStrokeStyle(
  [ref]          const D2D1_STROKE_STYLE_PROPERTIES &strokeStyleProperties,
  [in, optional] const FLOAT                        *dashes,
                       UINT                         dashesCount,
  [out]                ID2D1StrokeStyle             **strokeStyle
);

notice the second optional argument followed by two non-optional ones...how in the world am I supposed to use the function without passing the second argument, if it is on the middle?! x_x

That optional argument "const FLOAT *dashes" is a pointer. Means you can either supply actual data - array with dashes lengths, or not supply anything. For pointers/arrays that means passing zero/nullptr. You can't omit it in a sense of C/C++ optional arguments, but you can some give data or not, that's what "optional" means in this case.

Advertisement

Oh I see, I actually should have realized this, probably wasn't thinking straight :P

Thanks :)

Note that this is just a convention used in this particular documentation - there's no official "optional argument" in C++, except perhaps the case when you have function overloads with different length argument lists.

11 minutes ago, Kylotan said:

Note that this is just a convention used in this particular documentation - there's no official "optional argument" in C++, except perhaps the case when you have function overloads with different length argument lists.

I think I was under the assumption that optional referred to C++ "Default arguments" (because they are optional), but indeed not the case

True, I suppose they are optional to provide at the call-site.

This topic is closed to new replies.

Advertisement