StandardCplusplus icon indicating copy to clipboard operation
StandardCplusplus copied to clipboard

std::list<T> remove function is not working...

Open devenfan opened this issue 11 years ago • 1 comments

My Class Name: MyClass

Here is the code:

class MyCollection {

private:
    std::list<MyClass> m_list;

public:

    MyCollection() : m_list() {
    }

    void addMyClass(const MyClass & myClass) {
        m_list.push_back(myClass);
    }
    void addMyClass(const MyClass & myClass) {
        m_list.remove(myClass); //Error is occurred here
    }
}

Below is the error description:

StandardCplusplus-master/list:661: error: no match for 'operator==' in 'temp.std::list<T, Allocator>::iter_list::operator* [with T = MyClass, Allocator = std::allocator<MyClass>]() == value'

make: *** [MyLib.o] Error 1

devenfan avatar Mar 19 '13 09:03 devenfan

You need to define bool MyClass::operator==(const MyClass& other). This is not a library bug

eric-wieser avatar Jan 21 '14 18:01 eric-wieser

Thanks, @eric-wieser

maniacbug avatar Jul 05 '23 23:07 maniacbug