Archive for December, 2008

Ok, this should be a nobrainer for most of C# developers, me included. Still it happened to me and believe me I was dumbstruck.
I wrote a piece of code like the one below:

namespace TestInheritance
{
public class BaseClass
{
public BaseClass(string parameter) {}
}

public class ChildClass : BaseClass
{
public ChildClass() {}
}
}

Nothing special here but on compile time you get an error: “No overload for method ‘BaseClass’ takes ’0′ arguments“. Doh! how come? We don’t expect this to happen ussually but the little devil here is the inheritance and the non default constructor of the base class. When the constructor of the child class is called, it calls first the constructor of the base class with the same parameters. But if the compiler does detect a non default constructor it will not create the default one. So you get this error.

Cheers!

Comments No Comments »