I don't know C++ or its idioms, but modifying a global variable and then passing it to a function feels a bit awkward to me.