2019-12-15 10:59 AM
Hello All,
I made a C/C++ project with STM32CubeIde version 1.1.0. It works fine.
Then I added a C++ class by a cpp and hpp file. And tried to make an instance of the class in the main.c file. The compiler does not recognize "class" symbol in my hpp file. How to solve this?
Is there an coding example?
Thanks and regards,
Jens
arm-none-eabi-gcc "../Core/Src/main.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DUSE_HAL_DRIVER -DDEBUG -DSTM32F429xx -c -I../Middlewares/Third_Party/FreeRTOS/Source/include -I../Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -I../Drivers/CMSIS/Include -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Core/Inc -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Core/Src/main.d" -MT"Core/Src/main.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Core/Src/main.o"
In file included from ../Core/Src/main.c:25:0:
../Core/Src/CFlashLed.hpp:21:1: error: unknown type name 'class'
class CFlashLed
^~~~~
../Core/Src/CFlashLed.hpp:22:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
2019-12-15 11:19 AM
2019-12-15 01:35 PM
A .c file is considered to contain C source code, not C++ and class is not a keyword in C. What you can do, is calling a C++ free function in a separate .cpp file from main() which in turn instantiates an object of you class.
2021-05-07 07:19 PM
rename main.c to main.cpp