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

does header file support C++ instruction

i can not write cpp instruction in my header files like usual CPP ide (visual cpp) does keil support class definition just in X.cpp file ?

Parents
  • you can of course write C++ code in a header file, but if you do so then it can only be included from a C++ source file.

    there are a few exceptions to this in Keil, since it supports some C++ features even when compiling a C file, such as C++ style comments and anonymous unions / structures.

    this is actually really useful.

    But of course if you are building a project with existing C files and want to start using C++ features then you have to take care also with name mangling, so it's probably better to simply tell uVision that all files are to be compiled as C++ anyway.

    You can select the file type for any file in the project by changing it's options.

    regards

    Phil.

Reply
  • you can of course write C++ code in a header file, but if you do so then it can only be included from a C++ source file.

    there are a few exceptions to this in Keil, since it supports some C++ features even when compiling a C file, such as C++ style comments and anonymous unions / structures.

    this is actually really useful.

    But of course if you are building a project with existing C files and want to start using C++ features then you have to take care also with name mangling, so it's probably better to simply tell uVision that all files are to be compiled as C++ anyway.

    You can select the file type for any file in the project by changing it's options.

    regards

    Phil.

Children