I'm having issues while trying to get the typeid of an array. When I type typeid(*ptr[0]).name(), it works perfectly fine. but as soon as I change the 0 to a variable in a loop it gives me this error please help me!
#include "Cellphone.h"
#include "Electronic_device.h"
#include "Laptop.h"
#include "Smartwatch.h"
#include <vector>
#include <typeinfo>
int main()
{
string name;
int i = 0;
Electronic_device** ptr = new Electronic_device*[100];
Cellphone c1("Samsung", 1023, "black", 250.00, 1);
Smartwatch s1("IBM", 10, "red", 350.00, 2);
Laptop l1("HP", 102, "black", 1250.00, 16, true);
ptr[0] = &c1;
ptr[1] = &s1;
ptr[2] = &l1;
ptr[0]->print();
for (i = 0; i < sizeof(ptr); i++)
{
if (typeid(*ptr[i]) == typeid(Cellphone))
{
cout << "Cellphone" << endl;
}
if (typeid(*ptr[i]) == typeid(Smartwatch))
{
cout << "Smartwatch" << endl;
}
if (typeid(*ptr[i]) == typeid(Laptop))
{
cout << "Laptop" << endl;
}
}
((Cellphone *)ptr[0])->printCellphone();
}