P
Prakash Bande
Hi,
I have bool operator == (xx* obj, const string st). I have declared it
as friend of class xx. I am now able to do this:
xx ox;
string st;
if (&ox == st)
{
}
But, when I have a vector<xx*> and use stl find
string xyz;
vector<xx*>::iterator i = find(ii, xv.end(), xyz);
c:\program files\include\algorithm(43) : error C2679: binary '==' : no
operator defined which takes a right-hand operand of type 'const class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >' (or there is no acceptab
le conversion)
Here is a code snippet:
#include "stdafx.h"
#include <string>
#include <vector>
#include <iostream.h>
using namespace std;
class xx;
bool operator == (xx* obj, const string st);
#include <algorithm>
class xx
{
friend bool operator == (xx* obj, const string st);
private:
string ab;
int i;
public:
xx(string a);
};
xx::xx(string a)
{
ab = a;
}
bool operator == (xx* obj, const string st)
{
if (st == obj->ab)
return true;
return false;
}
int main(int argc, char* argv[])
{
printf("Hello World!\n");
vector<xx*> xv;
xx x1("some1");
xv.push_back(&x1);
xx x2("some2");
vector<xx*>::iterator ii = xv.begin();
string xyz = "some2";
if (*ii == xyz )
{
}
while (ii != xv.end())
{
vector<xx*>::iterator i = find(ii, xv.end(), xyz);
xx *f = *i;
ii = i;
ii++;
}
}
I have bool operator == (xx* obj, const string st). I have declared it
as friend of class xx. I am now able to do this:
xx ox;
string st;
if (&ox == st)
{
}
But, when I have a vector<xx*> and use stl find
string xyz;
vector<xx*>::iterator i = find(ii, xv.end(), xyz);
c:\program files\include\algorithm(43) : error C2679: binary '==' : no
operator defined which takes a right-hand operand of type 'const class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >' (or there is no acceptab
le conversion)
Here is a code snippet:
#include "stdafx.h"
#include <string>
#include <vector>
#include <iostream.h>
using namespace std;
class xx;
bool operator == (xx* obj, const string st);
#include <algorithm>
class xx
{
friend bool operator == (xx* obj, const string st);
private:
string ab;
int i;
public:
xx(string a);
};
xx::xx(string a)
{
ab = a;
}
bool operator == (xx* obj, const string st)
{
if (st == obj->ab)
return true;
return false;
}
int main(int argc, char* argv[])
{
printf("Hello World!\n");
vector<xx*> xv;
xx x1("some1");
xv.push_back(&x1);
xx x2("some2");
vector<xx*>::iterator ii = xv.begin();
string xyz = "some2";
if (*ii == xyz )
{
}
while (ii != xv.end())
{
vector<xx*>::iterator i = find(ii, xv.end(), xyz);
xx *f = *i;
ii = i;
ii++;
}
}