Dangerous!  Technically, these variables fall out of scope when you leave the if block, meaning that they could be destroyed (if the C++ compiler wants to do so).  I think you need to either make them globals or (more likely) pull them out ahead of the if statement.