【问题标题】:Cannot compare typedef string with == [closed]无法将 typedef 字符串与 == 进行比较 [关闭]
【发布时间】:2014-01-21 08:35:35
【问题描述】:

在我的程序中,我做到了

typedef std::string newName

我有一个方法,只要没有任何现有副本,我就需要将 newName 插入到 newName 类型的数组中。为此,我必须检查数组的每个元素。

bool insert(newName insertThis)
{
    if(arrayName[i] == insertThis)
        return false;
    ...
}

编译器说它不能用“==”比较两个 newName 对象,即使我使用 typedef 来表明 newName 与字符串相同。

【问题讨论】:

  • 发布一个完整但最小的例子
  • @Cheersandhth.-Alf 我一直认为你的名字是一个链接。
  • 并发布实际的错误信息。
  • 可能 arrayName[i] 不是 std::string
  • 这和你之前的问题stackoverflow.com/questions/21227789/…有关吗?如果是,这次请发布一些最小的示例。

标签: c++


【解决方案1】:

您仍然必须包含<string>

【讨论】:

  • +1 表示阅读他的完整代码。
猜你喜欢
  • 2013-07-28
  • 2020-06-08
  • 2015-01-18
  • 2018-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-05
  • 2021-09-04
相关资源
最近更新 更多