在调试程序时发现一个警告信息,无“0”参数的构造函数的信息。
如下例:
我定义了一个类如下
public class class1
{
string str;
public class1(string str)
{
this.str=str;
}
}
定义了一个类class2继承了class1
publice class class2:class1
{
char[] my;
int ind;
public class2(string str,int i)
{
my=str.TocharArray();
ind=i+str.length;
}
}
结果运行说类class1中没有0参数的构造函数!
提示该信息的原因是vs2008不提供默认的无0参数的构造函数。
所以为了申明实例时的兼容性,要求有一个0参数的构造函数。
修改方法:
在class中增加一个0参数构造函数。方法如下:
public class class1
{
string str;
publ class1()
{}
public class1(string str)
{
this.str=str;
}
}
本文介绍了在使用Visual Studio 2008进行编程时遇到的一个常见警告——类中缺少无参数构造函数,并给出了具体的解决办法。
2万+

被折叠的 条评论
为什么被折叠?



