我的程序遇到了一个奇怪的问题。因此,在头我有这样的事情:在我的Set1.cpp文件功能的1份没有运算符==匹配std :: string吗?
#ifndef SET1_INCLUDED
#define SET1_INCLUDED
#include <iostream>
using namespace std;
typedef std::string ItemType;
class Set1{
public:
------some public constructor and method in here-------
private:
ItemType setMember[100];
}
我得到了这样的事情:
if (setMember[i] == "foo") {exist = true;}
在这种情况下,我得到了一个错误消息说:“没有找到操作符找到类型为'ItemType'的左侧操作数”。但是,如果我将typedef中的std :: string更改为int或unsigned long,并将“foo”更改为某个随机数,则代码将完美工作。任何建议? thx
你是不是'#include'? –
billz
我不喜欢'使用namespace std'和'std :: string'组合(你应该使用其中一个)。但是,那可能只是我,其他人可能会不同意。 –