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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sandeep Kanwal

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

    Hello,

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

    Error : illegal operands 'GraphicDataLin kInfo' == 'const
    GraphicDataLink Info'
    (point of instantiation: 'main()')
    (instantiating: 'std::replace<s td::__wrap_iter ator<std::vecto r<GraphicDataLi nkInfo,
    std::allocator< GraphicDataLink Info>>, GraphicDataLink Info *>,
    GraphicDataLink Info>(std::__wr ap_iterator<std ::vector<Graphi cDataLinkInfo,
    std::allocator< GraphicDataLink Info>>, GraphicDataLink Info *>,
    std::__wrap_ite rator<std::vect or<GraphicDataL inkInfo,
    std::allocator< GraphicDataLink Info>>, GraphicDataLink Info *>, const
    GraphicDataLink Info &, const GraphicDataLink Info &)')
    algorithm line 1270 if (*first == old_value)

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

    class GraphicDataLink Info {
    public:
    GraphicDataLink Info() {}


    };

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

    GraphicDataLink Info test1;

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

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

    return 0;
    }

    Thanks
    ks
  • Alexander Burchak

    #2
    Re: std::replace() usage. what is wrong ?

    sandeep Kanwal wrote:
    [color=blue]
    > Hello,
    >
    > Just started using some STL stuff and I am getting some compiler error
    > as below Please guide...
    >
    > Error : illegal operands 'GraphicDataLin kInfo' == 'const[/color]

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

    class GraphicDataLink Info {
    public:
    GraphicDataLink Info() {}

    bool operator==(cons t class GraphicDataLink Info &gdli) {
    return gdli.some_membe r == some_member;
    }
    };

    Comment

    Working...