What's the right way to work with C++ project?
In STM32CubeIDE I created a C++ project. But the `main.c` is still generated with the .c extension and is compiled with the C compiler. That is why I cannot include the C++ headers to `main.c` (because the C compiler does not understand the keyword `class`). Thus I cannot create in `main.c` the global instances of the C++ classes.
I can tell the IDE to use the `g++` (C++) compiler for this file rather than `gcc` (C compiler). But among the language standard options still only the C options are available (e.g. "GNU11 (ISO C11 + gnu extensions) (-std=gnu11)"). The compiler will still compile the file as a C file rather than C++.
On the other hand I'm afraid to rename the `main.c` to `main.cpp` because it is regenerated during the code generation (after an update to .ioc file).
So how to make STM32CubeIDE to place the `main()` function to a C++ file, e.g. `main.cpp`, rather than to a C file like `main.c`?
---
My current idea is the following:
* tell IDE to exclude the `main.c` from compilation;
* copy `main.c` to `main.cpp`;
* include to `main.cpp` the C++ headers and create the instances of C++ classes, call their member functions from `main()` function;
* whenever the code is regenerated (and `main.c` is updated), copy the updates to `main.cpp`.
I hope there is a better approach than this. Please advise.