This is to be expected. The STM32CubeMX tool generates Plain C files, so placing C++ code in them will result in errors. You can still add .cpp files to the STM32CubeMX-generated projects as shown in our STM32CubeMX tutorial, however it will require carefully partitioning the code into Plain C and C++ parts, and declaring the functions that need to be visible from both parts with extern “C”.
As an alternative, please consider using the regular VisualGDB Embedded Project Wizard that can generate a C++ main file instead.