Which keyword is used to determine the datatype of a variable? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

10th Apr 2017, 1:22 PM
Mohammad Aaqib
Mohammad Aaqib - avatar
4 Answers
+ 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.
12th Apr 2017, 1:51 PM
Muhammad Aaqib
Muhammad Aaqib - avatar
+ 1
try to use the typeof() function bro
12th Apr 2017, 1:07 PM
CodeRoid - avatar
+ 1
quetta gladiators rock man me from quetta
12th Apr 2017, 1:08 PM
CodeRoid - avatar
- 2
12th Apr 2017, 5:30 PM
Giuseppe Di Stefano
Giuseppe Di Stefano - avatar