G
G
Georgy Kuznetsov2021-06-24 09:42:47
C++ / C#
Georgy Kuznetsov, 2021-06-24 09:42:47

Why is it a bad idea to use the crutch protected constructorName() {} inside the class in order to inherit this class from another?

Suppose the described class from which we want to inherit has only constructors with parameters (there is no point in using constructs without parameters)

But this approach may seem wrong to many, so how to make it possible not to cut such crutches? To make the code below look more adequate and everything compiles

Class A {
    protected A () {
    
    }
    public A (int _param) {
    
    }
}

class B : A
{

}


And of course it would be great to know why this approach is fundamentally wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-06-24
@JoeSmith3100

If a constructor without parameters doesn't make sense, then don't create it. In this case, the inheriting class will be required to take care of the arguments. And that's okay.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question