This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Identifier "class" is undefined

Hi everyone!
I am using MDK-ARM Lite Edition / uVision V5.22.0.0 and i am developing for a STM32F446 microcontroller.
I have a project consisting of *.c and *.h files that can be compiled without any problem.
Now i am trying to add one cplusplus file and one matching header file (MyClass.cpp and MyClass.h) to this existing project.
These two files contain the definition and the source code of my class.
When i include the header file in my main.c file (#include "MyClass.h"),
i receive the following error message when i try to compile my project again:
"MyClass.h(6): error: #20:identifier "class" is undefined"

The source code of MyClass.cpp and MyClass.h should be ok
because they can be compiled in an other project (also using MDK-ARM Lite Edition / uVision V5.22.0.0 ).

I am well are aware that a plain C compiler doesn't know the meaning of "class".

And i know "Google" but i cannot find the right magic words for getting a sufficient answer from that guy... :)

Crosschecked the Keil forum also without any luck.

In the project C/C++ settings i tried:
> disable C99 mode ===> no change, same error message
> --cpp and --cpp_compat ===> no change, same error message
> --gnu

I just want to tell MDK-ARM Lite Edition / uVision V5.22.0.0:
Please doen't use the C compiler, please use the C++ compiler,
in hope that the compiler will recognize the C++ keyword "class".

Can anyone please give my a hint?
Thanks in advance
Tobi

Parents
  • I even changed "main.c" to "main.cpp"
    ===>
    no change, same error message when compiling

    Even the MDK-ARM Lite Edition / uVision V5.22.0.0 IDE marks the source code
    in the "MyClass.h" file with a red cross for signaling an error:

    Source code:
    class MyClass
    { ...
    };

    IDE error message:
    "error: unknown type name 'class'"

    How to convince the IDE / compiler to accept this keyword?

Reply
  • I even changed "main.c" to "main.cpp"
    ===>
    no change, same error message when compiling

    Even the MDK-ARM Lite Edition / uVision V5.22.0.0 IDE marks the source code
    in the "MyClass.h" file with a red cross for signaling an error:

    Source code:
    class MyClass
    { ...
    };

    IDE error message:
    "error: unknown type name 'class'"

    How to convince the IDE / compiler to accept this keyword?

Children