C#中的继承问题,帮助! [英] An Inheritance problem in C#, help!

查看:63
本文介绍了C#中的继承问题,帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码无法在VS2008中成功构建,请帮助我,谢谢!

错误2``mSun''必须是具有公共无参数构造函数的非抽象类型,以便将其用作通用类型或方法``mBaseList< t>''中的参数``T''

The following code can''t be built successfully in VS2008, please help me, thanks!

Error 2 ''mSun'' must be a non-abstract type with a public parameterless constructor in order to use it as parameter ''T'' in the generic type or method ''mBaseList<t>''

class mBase
    {
        public string a;

    }

    class mBaseList<T> : List<T> where T : mBase, new()
    {
    }

    class mSun :mBase
    {
        public string b;

        public mSun(string b)
        {
            this.b = b;
        }
    }

    class mSunList : mBaseList<mSun>
    {
        public mSunList()
        {

        }

    }

推荐答案

您已将其设置为需要默认的构造函数(new()部分),但尚未提供一个.因此,要么做一个,要么取消对拥有一个的要求.
You have it set to require a default constructor (the new() part) yet you haven''t supplied one. So either make one, or remove the requirement to have one.


这篇关于C#中的继承问题,帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆