"error C2653: System is not a class or a namespace name"在窗体头文件、可视C++
"error C2653: System is not a class or a namespace name" in Form header file, Visual C++
我之前关于同一个项目的问题:第一和第二。没有必要去读它们;只知道我正试图在Visual c++项目中使用本地c++ SDK。这比我最初想象的要棘手得多,但是这个关于用托管代码扩展本地c++项目的网站已经帮助了我很多。
根据最后一个链接的说明,我在我的本地c++项目中添加了一个Form,它自动将项目转换为CLR。只有MainForm.cpp
和Interface.cpp
(允许本地c++代码创建和显示MainForm的文件)是用/clr
标志编译的;其他文件保持原生。
我现在的问题是,Visual Studio似乎不识别MainForm.h
中使用的任何CLR东西。因此,在以下行中:
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
字System
总是用红色下划线,有相应的错误:
error C2653: 'System' is not a class or a namespace name
它也不识别gcnew
这个词和其他应该在CLR中轻松工作的东西。
在哪里包含MainForm.h
-直接还是间接?
如果在Interface.h
中包含MainForm.h
,则在包含Interface.h
的任何地方也间接包含它。这意味着,如果你在任何没有使用/clr
编译的翻译单元(即*.cpp)中包含Interface.h
,那么编译器当然会抱怨它,因为namespace System
和gcnew
不是标准c++的一部分。
因此你应该只在Interface.cpp
中包含MainForm.h
,在Interface.h
中使用前向声明。
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 文本文件中的单词链表
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用新行和不使用新行读取文件
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 挂起和取消挂起一个文件DLL
- 如何确定我已使用非编码文件到达 EOF?
- 命名空间中具有.h和.cpp文件的类
- 如何使用ndk-build.cmd构建Android.so文件
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 读取文件并输入到矢量中
- 在C++中查找文件
- 如何在Windows窗体应用程序中打开txt文件并将行导入文本框
- 如何在 Windows 窗体中为事件函数定义使用单独的.cpp文件
- 在visual c++windows窗体应用程序中浏览文件
- 无法在Windows窗体项目中包含文件
- "error C2653: System is not a class or a namespace name"在窗体头文件、可视C++
- 如何在visual studio 2010中使用窗体应用程序按钮来运行控制台文件
- 如何在Visual c++ Windows窗体应用程序中包含文件