Click here to Skip to main content
15,885,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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>'

C#
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()
        {

        }

    }
Posted

1 solution

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.
 
Share this answer
 
Comments
virusx1984 18-Jul-12 19:04pm    
Could you give me the sample code ?
lewax00 18-Jul-12 20:18pm    
Just change
class mBaseList<t> : List<t> where T : mBase, new()
to
class mBaseList<t> : List<t> where T : mBase
virusx1984 19-Jul-12 9:39am    
If I want to make one, how should I do? Thanks a lot!
lewax00 19-Jul-12 9:42am    
Add a constructor to mSun with no parameters, i.e.
public mSun()

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900