In C# I know you can use the default keyword to assign default values as 0 to value types and null to reference types and for struct types individual members are assigned accordingly. To my knowledge there are no default values in C++. What approach would you take to get the same functionality as the default keyword for Generics while programming in C++?
Share
Assuming the type is default-constructible, you can use value initialization. For example,
If the type is not default-constructible, typically you need to provide a default to use. For example,
This function can be called with no argument if the type is default-constructible. For other types, you can provide a value to be returned.