I've just got a warning in my IDE that my class is abstract
but it is derived from concrete
class. And what? Why can't I do so? This suites my needs very well. It's just a warning though so the class is compilable. Just interested why it gives me this warning. Thank you.
Update
I need to extend my question with some explanations. I have this class derived from other class and I want nobody to be able to instantiate it. Moreover, I need two subclasses from this abstract class and each of them to have their own implementation of one abstract method. That's why.
Do you think it is bad idea? What approach shall I take instead?
In C#, two classes (either abstract or concrete) cannot be inherited by the same derived class.
An abstract method must be implemented in all non-abstract classes using the override keyword. After overriding, the abstract method is in the non-Abstract class. We can derive this class in another class, and again we can override the same abstract method with it.
Abstract class can have both an abstract as well as concrete methods. A concrete class can only have concrete methods. Even a single abstract method makes the class abstract. Abstract class can not be instantiated using new keyword.
Note that you can derive an abstract class from a nonabstract class, and you can override a non-pure virtual function with a pure virtual function. You can call member functions from a constructor or destructor of an abstract class.
I think the reason is maybe that abstract classes usually serve for basic behavior/information for creating subclasses. Think about other programmers while making such a decision. Others don't expect it.
Anyway, you can set compiler preferences not to give warnings for this type of "problem".
Update
After reading your update I think the simplest way is to declare this class's constructor protected
.
For the abstract method: you can simply override
that from your subclasses, I think.
You can do that. That's why you got a warning and not an error.
This is a common case and typically points to bad system architecture. That's why the compiler shows a warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With