Using classes/objects with CubeMX project
Hi all
I’ve spend countless hours on the internet trying to figure out how to use classes/objects (C++, I guess) with a project coming from CubeMX. I know this question has been asked several times before, but I simply do not understand how to make it work.
I simply want to add C++ files to the CubeMX project, and call a member function of an object from main() in main.c.
I’m on the latest releases of CubeMX and System Workbench, and I have converted the project to C++ using “Convert to C++” in System Workbench. I can add .cpp and .hpp files to the project, but how do I call the member function from main()?
I have the following CTerminal.hpp:
#ifndef CTerminal_H_ #define CTerminal_H_ class CTerminal { ... }; #endif
Eclipse says: unknown type name ‘class’
But... even if I get the above issue corrected, will the following main.c work (including a C++ file and instantiating an object within a C file)?
main.c
#include "main.h" #include "stm32f4xx_hal.h" #include "fatfs.h" #include "usb_device.h" /* USER CODE BEGIN Includes */ #include "CTerminal.hpp" ... int main(void) { /* USER CODE BEGIN 1 */ CTerminal Terminal; ... }
Thanks in advance!