【问题标题】:Ambiguous symbol String模棱两可的符号字符串
【发布时间】:2013-05-01 02:57:34
【问题描述】:

我正在用 c++/cli 编写一个程序,它给了我错误: 错误 C2872:“字符串”:不明确的符号

我使用 String 作为函数的一部分: Dictionary<String^, List<array< Byte >^>^>^ FalseTrigg(Dictionary<String^, String^>^ imgParms, bool windowOn)

以下是整个程序。感谢您的帮助。

 #include <errno.h>
 #include <vector>
 #include <string>
 #include <iostream>
 #include <sstream>
 #include <string>
 #include <fstream>

 #pragma managed(push, off)

 #include "cv.h" 
 #include "highgui.h" 
 #include <stdio.h>
 #include "opencv2/core/core.hpp"
 #include "opencv2/features2d/features2d.hpp"
 #include "opencv2/highgui/highgui.hpp"
 #include "opencv2/nonfree/nonfree.hpp"
 #include <opencv2/nonfree/features2d.hpp>

 #pragma managed(pop)

 using namespace cv;
 using namespace std;
 using namespace System;
 using namespace System::Collections::Generic;
 using namespace System::Runtime::InteropServices;


 public ref class FalseTrig
{
  public:
  FalseTrig() { } 
  ~FalseTrig() { } 

  Dictionary<String^, List<array< Byte >^>^>^ FalseTrigg(Dictionary<String^, String^>^ imgParms, bool windowOn) 
  {}
};

【问题讨论】:

    标签: c++-cli


    【解决方案1】:

    String 类有两个定义,编译器不知道你需要哪一个。错误消息应该有更多行,其中将列出它找到的各种“字符串”类。

    我不确定它找到了哪些定义,因为std::string 应该是小写的“s”,而您使用的是大写的“S”。

    在您的方法定义中,只需将String^ 替换为System::String^,就可以了。

    或者,您可以找出它正在查找的“字符串”类,并将您的 using namespace 指令更改为不使用包含其他字符串类的命名空间。您还可以使用 typedef 使 String 明确引用 System::String

    【讨论】:

      【解决方案2】:

      看起来你已经包含了两次 String 的定义。

      #include <errno.h>
      #include <vector>
      #include <string>  //-> First time
      #include <iostream>
      #include <sstream>
      #include <string>  //-> Second time
      #include <fstream>
      

      【讨论】:

      • &lt;string&gt; 头文件有适当的包含保护。包括它两次不会有任何伤害。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-05
      相关资源
      最近更新 更多