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

C++, works maybe?

I put a simple class in a file named "test.h". The class is as follows:

class a {
public: int b;
};

I am using the Keil MCBSTM32 board (STM32F103RB processor).

I place this file in "C:\Keil\ARM\Boards\Keil\MCBSTM32\Timer". I then open the timer project.

If I include the file in timer.c I get the following error:


Build target 'MCBSTM32'
compiling Timer.c...
test.h(2): error: #20: identifier "class" is undefined
test.h(2): error: #65: expected a ";"
Target not created

Why does it give me an error? I thought the compiler ssuported C++?

Parents
  • I did not realize that there was a possibility that the extension had anything to do with the compilers ability to recognise C++.

    As already pointed out, often a toolchain will make the decision whether to compile code as 'C' or 'C++' based on the extension as a default. I'm not familiar with the ARM toolchain, but you may well find that there is an option (probably available in the project options as well as a command line switch) to select 'C' or 'C++' compilation on a per-file basis, irrespective of extension.

Reply
  • I did not realize that there was a possibility that the extension had anything to do with the compilers ability to recognise C++.

    As already pointed out, often a toolchain will make the decision whether to compile code as 'C' or 'C++' based on the extension as a default. I'm not familiar with the ARM toolchain, but you may well find that there is an option (probably available in the project options as well as a command line switch) to select 'C' or 'C++' compilation on a per-file basis, irrespective of extension.

Children