The library says it returns as a void pointer, but what does that information return like? Does it return the name of the option that is put in with this,
autoChooser.AddObject(“Lowbar Auto”, new Auto);
“Lowbar Auto” is the name of the option, and can I use it in an if statement like,
if (autoChooser.GetSelected() == “Lowbar Auto”) {
//Stuff for lowbar auto
}
I haven’t used C++ for robot programming but being familiar with C and C++ APIs, it looks like it will return the object you passed in as the second parameter to AddObject().
This code:
if (autoChooser.GetSelected() == "Lowbar Auto") {
//Stuff for lowbar auto
}
would not work because it would compare the void* (address) to the address of the “Lowbar Auto” string literal (char*, wchar_t*, etc. depending on compiler). Instead, you should cast the return value of GetSelected() back to the pointer type which you passed in. Then you can dereference it, or do whatever else you need in order to decide what auto mode to run.
Also,
autoChooser.AddObject("Lowbar Auto", new Auto);
is likely to cause a memory leak since the SendableChooser won’t be able to delete the Auto as it will see it as a void*. You will probably need to manage that object yourself.