View Single Post
  #2   Spotlight this post!  
Unread 04-05-2016, 04:36 PM
heuristics heuristics is offline
Registered User
FRC #3634
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Trumbull, CT
Posts: 21
heuristics is on a distinguished road
Re: What does SendableChooser.GetSelected() return as?

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:
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,
Code:
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.
Reply With Quote