+ 2
Which keyword is used to determine the datatype of a variable?
Suppose we have 2 classes. One parent class and other inherited from that class. But now if we want to create a dynamic array of size 2. On index 0 we have created an object of base class but on index 1 we have created an object of derived class. Now we have 2 virtual function of same name and signature in both classes and want to have an if condition so that the function corresponding to class will be called. What would be the condition?
4 Respostas
+ 2
#include <typeinfo>
Declare a string and initialize it like that
string str = "class Datatype";
then set the if condition like this:
if(*(arr[index])).name() == str)
{
arr[index]->fun()
}
Now it will only call the function of ur desired class. Instead of Datatype in str, u have to write the name of ur class.
+ 1
try to use the typeof() function bro
+ 1
quetta gladiators rock man me from quetta
- 2
0