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.

[参考译文] 编译器/TMS570LS1114:ccthe 6.1 中未定义标识符"class"的问题

Guru**** 2394735 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/662301/compiler-tms570ls1114-the-question-about-the-identifier-class-is-undefined-in-the-ccsv6-1

部件号:TMS570LS1114

工具/软件:TI C/C++编译器

大家好,

我想使用C++来生成CCS 项目,但当我在 *.h文件中定义类时,如下所示:

 

*。h文件:

#ifndef main_work _H_
#define main_work _H_
#include "stdio.h"
#include <stdlib.h>

类Hjh

公开:
int add (int a,int b)(内部a,内部b)

返回(a + b);
}
};


#endif /* main_work _H_*/

和*。cpp文件:

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

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


int main_work (void){

同时(1)

hjh hjh;
AX = hjh.add(1, 2);


}
}

但错误将弹出,如图所示:

 为什么未定义类?

如果我在main.cpp中定义了如下所示的c代码,则没有任何错误:

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

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

类Hjh

公开:
int add (int a,int b)(内部a,内部b)

返回(a + b);
}
};


int main_work (void){

同时(1)

hjh hjh;
AX = hjh.add(1, 2);


}
}

附件是我的project.e2e.ti.com/.../C_2B002B00_Pj.rar

谁能帮助我?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    很遗憾,我无法再现此问题。  提供的项目没有按照您在文章开头显示的方式编写代码。  我更改了代码以匹配,它构建得很干净。   

    有一件事要考虑…… 如果#include main_work.h (文件)在扩展名为.c的文件中,而不是.cpp,则我会看到与您显示的错误类似的错误。  您是怎么做到的?

    谢谢,此致,

    -George

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好,George,

    我 感觉 pitye2e.ti.com/.../1731.C_2B002B00_Pj.rar ,回复帖子中的附件会重现该问题。

    如下所示;

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    sys_main.c文件包括main_work .h文件,而main_work.h文件中包含C++代码。  这不受支持。  当编译器看到扩展名.c时,它假定它看到的所有代码(无论是否按#include)都是C代码,而不是C++代码。  如果文件扩展名是.cpp,则相反。  有关更多详细信息 ,请参见ARM编译器手册中的指定文件名一节。

    谢谢,此致,

    -George