From the information you provide, it's not possible to suggest you a specific fix. I will give you some general guidelines.
In C++ there are pointers and references. Make sure to read about the difference between them, but the thing that matters is that pointers can be null and references cannot.
The second thing to know is that
dynamic_cast<type>(object) might fail when
object cannot be transformed into
type. If you use a pointer,
dynamic_cast<>() returns a null value, which you can later check. If you use a reference,
dynamic_cast<>() cannot return null (references cannot be null!), so C++ raises an exception called
std::bad_cast.
This issue has nothing to do specifically with ARGoS, it's just a C++ thing. A possible approach, without knowing your code, is to proceed as follows:
Code: Select all
CMyController1* c1 = dynamic_cast<CMyController1*>(&footbot.GetControllableEntity().GetController());
CMyController2* c2 = dynamic_cast<CMyController2*>(&footbot.GetControllableEntity().GetController());
if(c1 != nullptr) { ... the controller is of type CMyController1 }
if(c2 != nullptr) { ... the controller is of type CMyController2 }
I made ARGoS.