|try (Foo f = new Foo())
Foo *f = new Foo();
or, if 'Foo' is designed for RAII:
Use Java to C++ Converter to convert from Java to C++.
Java and C++ Equivalents
Copyright © 1997 – 2018 Tangible Software Solutions Inc.