Why am I getting a namespace identifier error?

人走茶凉 提交于 2019-12-11 01:37:52

问题


I am using Keil uVision and I keep getting this error:

C:\Keil_v5\ARM\ARMCC\bin\..\include\rw/_defs.h(781): error:  #20:
    identifier "namespace" is undefined

What could lead to this error? Isn´t namespace automatically defined?


回答1:


It looks like you are using C compilation for C++ code - check the compiler options.

In C++ namespace is a reserved word, but not in C, so the compiler will try to interpret it as an identifier rather than a keyword - which will then of course make no sense syntactically to a C compiler.




回答2:


You did not expose many details but my hunch is that you use a C compiler for your C++ program. There are no namespaces in C.

I could produce similar messages with this program:

namespace test {
}

Output:

$ gcc test.c
test.c:1:1: error: unknown type name 'namespace'
 namespace test {
 ^
test.c:1:16: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{
' token
namespace test {
            ^

Ideone link



来源:https://stackoverflow.com/questions/24488490/why-am-i-getting-a-namespace-identifier-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!