构造函数互相调用,编译失败了。该怎么处理
构造函数互相调用,编译失败了。
我尝试在一个有参的构造函数里面调用一个无参的构造函数,如下:
出错行的编译错误信息是:
error CS0103: The name 'b' does not exist in the current context
我的程序应该怎么改呢?
------解决方案--------------------
public b(bool v) : this()
{
m_b = true;
}
我尝试在一个有参的构造函数里面调用一个无参的构造函数,如下:
class b
{
public int m_i;
public int m_j;
public bool m_b;
public b()
{
m_i = 0;
m_j = 1;
}
public b(bool v)
{
b();//编译错误
m_b = true;
}
}
static void Main(string[] args)
{
b obj = new b();
}
出错行的编译错误信息是:
error CS0103: The name 'b' does not exist in the current context
我的程序应该怎么改呢?
------解决方案--------------------
public b(bool v) : this()
{
m_b = true;
}