Quick Ctor Question

I have a base class that has a specific parameterized ctor. I use it as the base for several concretes. These concretes have zero need to alter ctor behaviour, and thusly, I see no reason to define one. However, as you may guess, I get the “class has no ctor that takes 0 arguments” error on compile.

Is there a keyword I can place on the base class ctor that will prevent the error? Or maybe another way around it?

This is indenpendant on any ioc usage by the way. It’s merely a set of objects that MUST take an argument, and it so happens, the base class handles everything that it needs. The derivations simply no reason to re-declare the ctor, just to pass it on to base();

Thanks.

Lots of ways to skin this cat. Keyword way is to do something like:


public class TheBase
{
    public TheBase(string s) { }
}

public class TheInheritor : TheBase
{
    public TheInheritor() : base(string.Empty) { }
}

That’s the way they currently are, and what I am trying to avoid. I want something more like:

public abstract class Formatter
{
public Formatter(object source) { }
public abstract string Reformat();
}

public SampleFormatter : Formatter
{
public override Reformat(){}
}

Have all derivatives inherit the base class ctor -without- redifining it?

you can’t… only a derived class can call the constructor of an abstract class