Answered by:
Optional parameters for WinRT component

Question
-
Hello,
I have this method signature:
void createThumbnail(Platform::String^ thumbnailPath, int size);
and would like the size param to be optional with a default value. Is that possible?
Friday, March 2, 2012 2:44 PM
Answers
-
You can use the defualt argument for a private function in winrt component. But if the function is public, it means that this function with default arguments can be called across the component, which is not allowed.
Best Regards,
Han XIa- Marked as answer by DavidLambMicrosoft employee, Moderator Monday, March 5, 2012 3:01 PM
Monday, March 5, 2012 2:26 PMModerator
All replies
-
Try this:
void createThumbnail(Platform::String^ thumbnailPath, int size = 1);
Read the 'Note these points when using default arguments' section in this document: Default Arguments for specific rules.
Thanks,
-David
- Proposed as answer by Jesse Jiang Monday, March 5, 2012 9:02 AM
- Unproposed as answer by DavidLambMicrosoft employee, Moderator Monday, March 5, 2012 3:01 PM
Friday, March 2, 2012 11:42 PMModerator -
Thanks David, I tried this (standard c++) and I got:
Error 1 error C3222: 'size' : cannot declare default arguments for member functions of a WinRT type or generic functions
:/
Friday, March 2, 2012 11:54 PM -
Hello,
I cannot reproduce your issue on my site. Would you please show us the whole codes to reproduce this issue?
Best regards,
JesseJesse Jiang [MSFT]
MSDN Community Support | Feedback to us
Monday, March 5, 2012 9:02 AM -
You can use the defualt argument for a private function in winrt component. But if the function is public, it means that this function with default arguments can be called across the component, which is not allowed.
Best Regards,
Han XIa- Marked as answer by DavidLambMicrosoft employee, Moderator Monday, March 5, 2012 3:01 PM
Monday, March 5, 2012 2:26 PMModerator -
@phil_ke I see what you were trying to do now. As Han Xi mentioned, default or optional parameters are not supported on the WinRT surface. Using them internally works fine, but not on the surface of your WinRT component.
Thanks,
-David
Monday, March 5, 2012 3:01 PMModerator -
Pitty. In my own Active/JavaScript-COM Wrapper I handled empty arguments, since that is part of COM already. The compiler that generates the "winmd" file could certainly substitute empty VARIANT arguments coming from JavaScript with the defined default parameter as well. But I guess we have to live with that now. No big deal.Monday, March 5, 2012 5:09 PM