This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TMS570LS1114: The question about the identifier "class" is undefined in the ccsv6.1

Part Number: TMS570LS1114


Tool/software: TI C/C++ Compiler

Hi Guys,

I wanna use the C++ to build the ccs  project, but when i define the class in the  *.h file,such as below:

 

*.h file:

#ifndef MAIN_WORK_H_
#define MAIN_WORK_H_
#include "stdio.h"
#include <stdlib.h>

class HJH
{
public:
int add(int a, int b)
{
return (a + b);
}
};


#endif /* MAIN_WORK_H_ */

and the *.cpp file:

/*
* main.cpp
*/
#include "iostream"
#include "stdio.h"
#include <stdlib.h>
#include "main_work.h"

extern "C" int main_work(void);
int ax=0;


int main_work(void) {

while(1)
{
HJH hjh;
ax = hjh.add(1, 2);


}
}

but the error will pop up shown as the picture:

why the class is undefined?

and if i defined the c code shown as below in the main.cpp,there is not any error :

/*
* main.cpp
*/
#include "iostream"
#include "stdio.h"
#include <stdlib.h>
#include "main_work.h"

extern "C" int main_work(void);
int ax=0;

class HJH
{
public:
int add(int a, int b)
{
return (a + b);
}
};


int main_work(void) {

while(1)
{
HJH hjh;
ax = hjh.add(1, 2);


}
}

the attachment is my project.C++Pj.rar

who can help me ?

  • Unfortunately, I am unable to reproduce the problem.  The project, as supplied, does not have the code written in the manner which you show at the beginning of your post.  I changed the code to match, and it builds clean.  

    One thing to consider ... If you #include main_work.h (the header file) in a file with the extension .c, and not .cpp, then I would expect errors similar to the ones you show.  Did you do that somehow?

    Thanks and regards,

    -George

  • Hi George,

    I feel pity1731.C++Pj.rar ,the attachment in the reply post will reproduce the problem.

    shown as below;

  • The file sys_main.c includes the file main_work.h, and main_work.h has C++ code in it.  This is not supported.  When the compiler sees the extension .c, it presumes all the code it sees, whether by #include or not, is C code, and not C++ code.  The opposite is true if the file extension is .cpp.  For more details, see the section titled Specifying Filenames in the ARM compiler manual.

    Thanks and regards,

    -George