abstract class CAbstract
{
private string mParam1;
public CAbstract(string param1)
{
mParam1 = param1;
}
}
class CBase : CAbstract
{
}
For the class CBase, it should be initialized by providing the parameter, so how to disable the parameterless constructor for CBase class?
If you define a parameterized constructor in
CBase, there is no default constructor. You do not need to do anything special.If your intention is for all derived classes of
CAbstractto implement a parameterized constructor, that is not something you can (cleanly) accomplish. The derived types have freedom to provide their own members, including constructor overloads.The only thing required of them is that if
CAbstractonly exposes a parameterized constructor, the constructors of derived types must invoke it directly.