Quote:
Originally Posted by Joe Ross
Here's code that works:
Code:
lw->AddActuator("Subsystem 1", "Speed Controller 1", std::static_pointer_cast<Talon>(subsystem1SpeedController1));
I'm not a C++ guru, so I'm not sure if that's the right method to cast the shared_pointer from a SpeedController to Talon or other class that implements a SpeedController.
|
I think std::static_pointer_cast will work here. The type is definitely a Talon, so std::dynamic_pointer_cast isn't necessary. Note that the pointer passed in can't be that of a stack allocated object or a double-free would occur later.
Quote:
Originally Posted by Joe Ross
Here's the code that causes the crash:
Code:
lw->AddActuator("Subsystem 1", "Speed Controller 1", (Talon&)subsystem1SpeedController1);
|
Is subsystem1SpeedController1 an object or pointer to an object? If the suggested code is correct, then subsystem1SpeedController1 is a pointer and casting to Talon& seems strange to me anyway.