|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 – 2021 Tangible Software Solutions, Inc.