Borrowing problem from porting some C++ code