mercredi 14 novembre 2018

Copy assignment operator, vector

I have this vector that hold values (Not on the Heap!)

std::vector<Dish> menu;

I want to implement copy assignment operator like this:

    Restaurant &Restaurant::operator=(Restaurant &&other) {
    if (this == &other)
        return *this;
    open = other.open;
    menu.clear();
    menu = other.menu;
    menu = std::move(other.menu);
}

I get those error/warnings:

        ^
/Users/avivlevitzky/CLionProjects/SPL-Project-1/Restaurant.cpp:49:10: note: in instantiation of member function 'std::__1::vector<Dish, std::__1::allocator<Dish> >::operator=' requested here
    menu = other.menu;
         ^
/Users/avivlevitzky/CLionProjects/SPL-Project-1/Dish.h:18:15: note: copy assignment operator of 'Dish' is implicitly deleted because field 'id' is of const-qualified type 'const int'
    const int id;

What's wrong??

Aucun commentaire:

Enregistrer un commentaire