Do you have anything written in C++ at the moment? The reason I ask is that the code you posted feels a bit taken out of its context.
Why are you looking to convert that piece of code to C++?