std::replace() usage. what is wrong ?

S

sandeep Kanwal

Hello,

Just started using some STL stuff and I am getting some compiler error
as below Please guide...

Error : illegal operands 'GraphicDataLinkInfo' == 'const
GraphicDataLinkInfo'
(point of instantiation: 'main()')
(instantiating: 'std::replace<std::__wrap_iterator<std::vector<GraphicDataLinkInfo,
std::allocator<GraphicDataLinkInfo>>, GraphicDataLinkInfo *>,
GraphicDataLinkInfo>(std::__wrap_iterator<std::vector<GraphicDataLinkInfo,
std::allocator<GraphicDataLinkInfo>>, GraphicDataLinkInfo *>,
std::__wrap_iterator<std::vector<GraphicDataLinkInfo,
std::allocator<GraphicDataLinkInfo>>, GraphicDataLinkInfo *>, const
GraphicDataLinkInfo &, const GraphicDataLinkInfo &)')
algorithm line 1270 if (*first == old_value)

#include <vector>
#include <algorithm>
#include <iostream>

class GraphicDataLinkInfo {
public:
GraphicDataLinkInfo() {}


};

int main()
{
using namespace std;
vector<GraphicDataLinkInfo> test;

GraphicDataLinkInfo test1;

std::replace(test.begin(), test.end(), test1, test1);

cout << "Hello World, this is CodeWarrior!" << endl;

return 0;
}

Thanks
ks
 
A

Alexander Burchak

sandeep said:
Hello,

Just started using some STL stuff and I am getting some compiler error
as below Please guide...

Error : illegal operands 'GraphicDataLinkInfo' == 'const

Operator == is not defined for class GraphicDataLinkInfo.
You have to define it, something like this:

class GraphicDataLinkInfo {
public:
GraphicDataLinkInfo() {}

bool operator==(const class GraphicDataLinkInfo &gdli) {
return gdli.some_member == some_member;
}
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,512
Latest member
FinleyNick

Latest Threads

Top