Answer the question
In order to leave comments, you need to log in
About inheritance in OOP. How can I get the name of a derived class from a base class?
Good afternoon!
There is a base class and n-th number of derivatives. The base class is abstract (but that doesn't matter) while providing a non-virtual function.
class Base()
{
...
void f();
...
}
class Der1(): public Base
{ ... }
class Der2(): public Base
{ ... }
Base* base = new Der1;
base->f();
Answer the question
In order to leave comments, you need to log in
If it's C++, then there is no good option.
You can use dynamic_cast to cast back a type or a typeid ( msdn.microsoft.com/en-us/library/fyf39xec.aspx ).
As for me, the best option is to fence your virtual functions that need to be redefined.
And what kind of task, where is this needed?
In the overwhelming majority of cases, if this is necessary, then this indicates a flawed program architecture, most likely the task can be solved much more elegantly without resorting to such nonsense.
About inheritance in OOP (find the name of a derived class from a base class)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question