It does have optional arguments, they just don't look the same way as the C++ syntax. Optional arguments are a language interop problem. It must be implemented by the language that makes the call, it generates the code that actually uses the default argument. Which is a tricky problem in a language that was designed to make interop easy, like C++/CLI, you of course don't know what language is going to make the call. Or if it even has syntax for optional arguments. The C# language didn't until version 4 for example.
And if the language does support it, how that compiler knows what the default value is. Notable is that VB.NET and C# v4 chose different strategies, VB.NET uses an attribute, C# uses a modopt.
You can use the [DefaultParameterValue] attribute in C++/CLI. But you shouldn't, the outcome is not predictable.
ref-class
specific anyway (C++ semantics have nothing to do with it), so they could just have provided the matching semantics. However, they didn't. – Lussiint
toSystem::Int32
? – Recessionaltemplate
vsgeneric
,*
vs^
,&
vs%
. Admittedly the destructor syntax is overloaded to do two different things, but it's the exception rather than the rule. The accepted answer basically makes the same point: C++ default arguments are basically liketemplate
s and CLR default arguments are likegeneric
s, in that the former don't exist past compile-time and the latter do... – Emulsifiertemplate
keyword forgeneric
s; they're superficially similar but have different semantics so reusing the same syntax without disambiguating the two would not have been appropriate. – Emulsifiertemplate
s over managed types are possible but aren't understood by non-C++/CLI code, but I can see why they didn't do that. – Emulsifier