lundi 26 juillet 2021

How to check if object is castable?

I have following classes:

class ATemperatureDevice{};
class AHumidityDevice{};

class BluetoothLeDevice{};

class Sensor1 : BluetoothLeDevice, ATemperatureDevice, AHumidityDevice {};
class Sensor2 : BluetoothLeDevice, AHumidityDevice  {};

I have a vector<BluetoothLeDevice>, where all devices are stored.

The Classes ATemperatureDevice, AHumidityDevice and BluetoothLeDevice have virtual functions.

When I pick one, I have a BluetoothLeDevice. Now I want to check if it derives from ATemperatureDevice and/or AHumidityDevice.

I tried dynamic_cast, when its not castable, I should get null but, it says "'dynamic_cast' not permitted with -fno-rtti" although they have virtual functions.

What's the best way to check and cast?

Aucun commentaire:

Enregistrer un commentaire