2

Here in this link it says:

The static_cast keyword can be used for any normal conversion between types. Conversions that rely on static (compile-time) type information. This includes any casts between numeric types, casts of pointers and references up the hierarchy, conversions with unary constructor, conversions with conversion operator. For conversions between numeric types no runtime checks if data fits the new type is performed. Conversion with unary constructor would be performed even if it is declared as explicit.

Also here:

To interoperate well with other CLS-compliant languages, you may wish to wrap each user-defined unary constructor for a given class with a corresponding convert-from operator.

What do they mean by "Unary Constructor"?

StackExchange123
  • 1,871
  • 9
  • 24

2 Answers2

7

Unary means one, so what they are talking about is a constructor with a single parameter. The standard name for such a thing is a conversion constructor.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
  • Though the same. You will sometimes hear it in combination with lambdas "unary lambda" function. – M.Mac Apr 16 '20 at 18:10
  • Converting constructors are required to not be explicit, so maybe unary constructor is broader than that. – cigien Apr 16 '20 at 18:10
  • @cigien Well in contexts of a static cast, you are being explicit so they still count. – NathanOliver Apr 16 '20 at 18:10
  • Extra default parameters would also work for conversion, even if I won't call them unary... But default constructor work the same way (but default doesn't mean zero :) )... – Jarod42 Apr 16 '20 at 18:38
2

Unary refers to one or singular, so a 'Unary constructor' ideally refers to a constructor with a single parameter.