“错误C2653:系统不是类或命名空间名称”在Form头文件中,Visual C ++ [英] "error C2653: System is not a class or a namespace name" in Form header file, Visual C++
问题描述
我关于同一项目的以前的问题:一个和两个。没有必要读它们;只是知道我试图在Visual C ++项目中使用本机C ++ SDK。这比我最初想的要复杂得多,但这个网站关于用托管代码扩展本地C ++项目已经帮助我了很多。
按照最后一个链接的说明,我已经添加了一个窗体到我的本地C + +项目,它已经自动转换为一个CLR项目。只有 MainForm.cpp
和 Interface.cpp
(允许本地C ++代码创建和显示MainForm的文件)编译时使用 / clr
标志;其他文件保持原生。
我现在的问题是,Visual Studio似乎不认识任何在 MainForm.h
。因此,在以下行中:
使用命名空间System;
using namespace System :: ComponentModel;
using namespace System :: Collections;
using namespace System :: Windows :: Forms;
using namespace System :: Data;
using namespace System :: Drawing;
单词系统
,根据错误:
错误C2653:'System'不是类或命名空间名称
$
它也不能识别这个字符。c $ c>
< gcnew
和其他应该在CLR中毫不费力地工作。
任何人都可以告诉我我可能做错了什么?我的猜测是,它的东西很小;一些标志我忘了改变,一个缺失的引用或类似的东西,但我只是不能弄清楚它是什么。
解决方案 p>您在哪里包含 MainForm.h
- 直接和间接?
如果包括 MainForm.h
在 Interface.h
中,您可以间接地包括 Interface.h
。这意味着,如果你在任何翻译单元(即* .cpp)中包含 Interface.h
,而不是使用 / clr
,那么编译器当然会抱怨,因为命名空间System
和 gcnew
不是标准的一部分因此,您应该包括 MainForm.h
仅在 Interface.cpp code>并在 Interface.h
中使用向前声明。
My previous questions concerning the same project: one and two. It's not necessary to read them; just know that I am trying to use a native C++ SDK in a Visual C++ project. This is much trickier than I had initially thought, but this website about Extending a native C++ project with managed code has helped me a lot further already.
As per that last link's instructions, I have added a Form to my native C++ project, which has automatically converted the project to a CLR one. Only MainForm.cpp
and Interface.cpp
(the file that allows native C++ code to create and show a MainForm) are compiled with the /clr
flag though; the other files remain native.
The problem I have now, is that Visual Studio doesn't seem to recognise any of the CLR stuff that's being used in MainForm.h
. As such, in the following lines:
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
the word System
is always underlined in red, with according errors:
error C2653: 'System' is not a class or a namespace name
for each of those lines.
It also does not recognise the word gcnew
and other things that should work effortlessly inside CLR.
Can anybody tell me what I might be doing wrong? My guess is that it's something very small; some flag I have forgotten to change, a missing reference or something similar, but I just can't figure out what it is.
解决方案 Where do you include MainForm.h
- directly and indirectly?
If you include MainForm.h
in Interface.h
, you include it indirectly anywhere where you include Interface.h
as well. That means, if you then include Interface.h
in any translation unit (i.e. *.cpp) that is not compiled with /clr
, then the compiler will of course complain about it, because namespace System
and gcnew
are not part of standard C++.
Therefore you should include MainForm.h
only in Interface.cpp
and use forward declarations in Interface.h
.
这篇关于“错误C2653:系统不是类或命名空间名称”在Form头文件中,Visual C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!