|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 © 2004 – 2019 Tangible Software Solutions, Inc.