本文介绍了使用marshal.h编译时出现问题:错误C2872:“ IServiceProvider”:不明确的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的C ++ / CLI项目中使用编组库。当使用 #include< msclr / marshal.h> 编译时,出现错误 error C2872:'IServiceProvider':模糊符号。大部分决议似乎都建议将 #include< windows.h>
移到此处-> ,但我没有这些包含。我所拥有的是:

I am trying to use the marshalling library in my C++/CLI project. When compiled with #include <msclr/marshal.h> I get the error error C2872: 'IServiceProvider' : ambiguous symbol. Most of the resolutions seems to be suggesting moving #include <windows.h>like the one here -> Ambiguous references, but I dont have those includes. All I have is:

using namespace System;
using namespace System::Configuration;
using namespace std;
#include <msclr/marshal.h>

如何调试此问题?

推荐答案

您可以间接将marshal.h包括在内。它在全局名称空间中转储了大量标识符。宏特别笨拙,其中许多与框架中使用的名称匹配。

You do, indirectly, marshal.h includes it. It dumps an enormous amount of identifiers in the global namespace. The macros are especially awkward, lots of them match names used in the framework.

marshal.h所做的许多事情也可以由Marshal类完成。但是,我对此无能为力,您也没有提及为什么要使用它。您可以通过在using语句中放置#include指令之前来解决这一特殊的事故:

Lots of things that marshal.h does can be done by the Marshal class as well. But I can't help you with that, you didn't mention why you want to use it. You can solve this particular mishap by putting the #include directive before the using statements:

#include <msclr/marshal.h>
using namespace System;
using namespace System::Configuration;

这篇关于使用marshal.h编译时出现问题:错误C2872:“ IServiceProvider”:不明确的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:09