[英]parameter with default object value
I have a class and function 我有一个班级和职能
class A
{
A(int i = 0)
{
}
}
void f(A a = new A(10)) // ? default parameter value must be compiler-time constanct
{
}
How to workaround it? 如何解决呢?
You would need to do it inside the method and provide a comment that the method accepts null and uses A(10)
as a default value. 您将需要在方法内部执行此操作,并提供注释,说明该方法接受null并使用
A(10)
作为默认值。
void f(A a = null)
{
if(a == null)
a = new A(10);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.