Code porting from Java to C++