Winforms Windows窗体应用程序中有许多不明确的符号 < >创建C++表单应用程序,我开始获得一些模糊不清的符号错误。但我不太清楚是什么原因造成的,它在早些时候还不错,但我可能改变了什么

Winforms Windows窗体应用程序中有许多不明确的符号 < >创建C++表单应用程序,我开始获得一些模糊不清的符号错误。但我不太清楚是什么原因造成的,它在早些时候还不错,但我可能改变了什么,winforms,c++-cli,directx-11,Winforms,C++ Cli,Directx 11,错误本身: 1>Application.cpp 1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(4089): error C2872: 'IDropTarget': ambiguous symbol 1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\oleidl.h(3508): note: could

错误本身:

1>Application.cpp
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(4089): error C2872: 'IDropTarget': ambiguous symbol
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\oleidl.h(3508): note: could be 'IDropTarget'
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(4089): note: or       'System::Windows::Forms::IDropTarget'
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(6496): error C2872: 'IServiceProvider': ambiguous symbol
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\servprov.h(98): note: could be 'IServiceProvider'
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(6496): note: or       'System::IServiceProvider'
1>main.cpp
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(4089): error C2872: 'IDropTarget': ambiguous symbol
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\oleidl.h(3508): note: could be 'IDropTarget'
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(4089): note: or       'System::Windows::Forms::IDropTarget'
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(6496): error C2872: 'IServiceProvider': ambiguous symbol
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\servprov.h(98): note: could be 'IServiceProvider'
1>c:\program files (x86)\windows kits\10\include\10.0.15063.0\um\ocidl.h(6496): note: or       'System::IServiceProvider'
我发现这很奇怪,因为我的表单没有包含任何这些文件,我想这是因为名称空间。我只是不知道这到底是从哪里来的

这是我的信息表格:

#include <Windows.h>

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

public ref class CFormController : public Form
{
public:
    CFormController(void)
    {
        InitializeComponent();
    }
    ~CFormController()
    {
        delete components;
    }

    System::ComponentModel::Container ^components;

    void InitializeComponent(void)
    {
        this->components = gcnew System::ComponentModel::Container();
        this->Size = System::Drawing::Size(300, 300);
        this->Text = L"FormController";
        this->Padding = System::Windows::Forms::Padding(0);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    }
};
#包括
使用名称空间系统;
使用名称空间System::ComponentModel;
使用名称空间系统::集合;
使用命名空间System::Windows::Forms;
使用名称空间System::Data;
使用名称空间系统::绘图;
公共引用类CFormController:公共窗体
{
公众:
CFORM控制器(无效)
{
初始化组件();
}
~CFormController()
{
删除组件;
}
系统::组件模型::容器^组件;
void初始化组件(void)
{
这->组件=gcnewsystem::ComponentModel::Container();
该->尺寸=系统::图纸::尺寸(300300);
此->文本=L“FormController”;
这->填充=System::Windows::Forms::Padding(0);
这->AutoScaleMode=System::Windows::Forms::AutoScaleMode::Font;
}
};
关于我的表格的唯一其他信息是在另一个类中。这仅用于显示或隐藏它


我发现了类似的问题,人们在“使用名称空间…”之前没有包含windows标题,但正如您所看到的,我添加了include,这没有任何区别。

您正在将冲突符号导入全局名称空间

如果您发布的代码是编译单元中包含的第一个文件,那么它应该可以。如果情况并非如此(例如,在发布头文件之前包含了另一个头文件),则在包含windows.h时,全局命名空间中可能已经存在WinForms类型,并导致C2872

可以将using语句或windows.h include移动到命名空间中以避免冲突。 e、 g


或者,如果确实要将类型导入全局名称空间,请将代码分成两个cpp文件,然后一次导入一个

C++/CLI因符号冲突而臭名昭著,每当您“使用”许多C#名称空间时。显然,System和System::Windows::Forms之间存在冲突。尝试删除后一个“using”声明,并通过使用System::Windows::Forms:作为前缀来指定此命名空间中的符号。我知道这是一个巨大的痛苦,但据我所知,没有其他解决办法


当我需要从Soe::Cuffes:Guang.

类时,我经常面对这个问题。这不是C++。这是C++/CLI。对不起,我不知道需要额外的标签,不需要额外的标签。正如我前面提到的,因为这不是C++,所以需要删除C++标签,用C++ +CLI标签替换,因为它是,问题是什么?C++ + CLI。
namespace Win32 {
#include "windows.h"
}
namespace ProjectName {

using namespace System;
......
}