Deleted function build fail












-2















im new to c++ and getting the error on my project that represents a resturant:




error: use of deleted function ‘Dish& Dish::operator=(const Dish&)’
*__result = *__first;

In file included from /users/studs/bsc/2019/romid/CLionProjects/rest/src/../include/Customer.h:9:0,
from /users/studs/bsc/2019/romid/CLionProjects/rest/src/../include/Action.h:9,
from /users/studs/bsc/2019/romid/CLionProjects/rest/src/Action.cpp:1:
/users/studs/bsc/2019/romid/CLionProjects/rest/src/../include/Dish.h:19:7: note: ‘Dish& Dish::operator=(const Dish&)’ is implicitly deleted because the default definition would be ill-formed:
class Dish{
^~~~



i cant understand which class cause the problem or what is the problem .
this is part the dish.cpp class.



 #include "../include/Dish.h";
#include <iostream>

Dish::Dish(int d_id, std::string d_name, int d_price, DishType d_type) :
id(d_id), name(d_name)
price(d_price), type(d_type){}

int Dish::getId() const
{
return id;
}

std::string Dish::getName() const {return name;}

int Dish::getPrice() const {return price;}

DishType Dish::getType() const {return type;}


this is the dish.h header file :



#ifndef DISH_H_
#define DISH_H_

#include <string>

enum DishType{
VEG, SPC, BVG, ALC
};

class Dish{
public:
Dish(int d_id, std::string d_name, int d_price, DishType d_type);
int getId() const;
std::string getName() const;
int getPrice() const;
DishType getType() const;
private:
const int id;
const std::string name;
const int price;
const DishType type;
};


#endif









share|improve this question

























  • Are any of your member variables constants or references?

    – Neil Butterworth
    Nov 13 '18 at 18:09











  • all of them are const ( d_name , d_price , d_type, d_id)

    – Dor Birendorf
    Nov 13 '18 at 18:11











  • @DorBirendorf Those are arguments, not members.

    – François Andrieux
    Nov 13 '18 at 18:12











  • Then how are you intending to assign to them? Remove the const qualifier.

    – Neil Butterworth
    Nov 13 '18 at 18:12






  • 1





    no need to approve edits from users with high reputation they are applied automatically, you only need to approve edits from newer users

    – Alan Birtles
    Nov 13 '18 at 18:54
















-2















im new to c++ and getting the error on my project that represents a resturant:




error: use of deleted function ‘Dish& Dish::operator=(const Dish&)’
*__result = *__first;

In file included from /users/studs/bsc/2019/romid/CLionProjects/rest/src/../include/Customer.h:9:0,
from /users/studs/bsc/2019/romid/CLionProjects/rest/src/../include/Action.h:9,
from /users/studs/bsc/2019/romid/CLionProjects/rest/src/Action.cpp:1:
/users/studs/bsc/2019/romid/CLionProjects/rest/src/../include/Dish.h:19:7: note: ‘Dish& Dish::operator=(const Dish&)’ is implicitly deleted because the default definition would be ill-formed:
class Dish{
^~~~



i cant understand which class cause the problem or what is the problem .
this is part the dish.cpp class.



 #include "../include/Dish.h";
#include <iostream>

Dish::Dish(int d_id, std::string d_name, int d_price, DishType d_type) :
id(d_id), name(d_name)
price(d_price), type(d_type){}

int Dish::getId() const
{
return id;
}

std::string Dish::getName() const {return name;}

int Dish::getPrice() const {return price;}

DishType Dish::getType() const {return type;}


this is the dish.h header file :



#ifndef DISH_H_
#define DISH_H_

#include <string>

enum DishType{
VEG, SPC, BVG, ALC
};

class Dish{
public:
Dish(int d_id, std::string d_name, int d_price, DishType d_type);
int getId() const;
std::string getName() const;
int getPrice() const;
DishType getType() const;
private:
const int id;
const std::string name;
const int price;
const DishType type;
};


#endif









share|improve this question

























  • Are any of your member variables constants or references?

    – Neil Butterworth
    Nov 13 '18 at 18:09











  • all of them are const ( d_name , d_price , d_type, d_id)

    – Dor Birendorf
    Nov 13 '18 at 18:11











  • @DorBirendorf Those are arguments, not members.

    – François Andrieux
    Nov 13 '18 at 18:12











  • Then how are you intending to assign to them? Remove the const qualifier.

    – Neil Butterworth
    Nov 13 '18 at 18:12






  • 1





    no need to approve edits from users with high reputation they are applied automatically, you only need to approve edits from newer users

    – Alan Birtles
    Nov 13 '18 at 18:54














-2












-2








-2








im new to c++ and getting the error on my project that represents a resturant:




error: use of deleted function ‘Dish& Dish::operator=(const Dish&)’
*__result = *__first;

In file included from /users/studs/bsc/2019/romid/CLionProjects/rest/src/../include/Customer.h:9:0,
from /users/studs/bsc/2019/romid/CLionProjects/rest/src/../include/Action.h:9,
from /users/studs/bsc/2019/romid/CLionProjects/rest/src/Action.cpp:1:
/users/studs/bsc/2019/romid/CLionProjects/rest/src/../include/Dish.h:19:7: note: ‘Dish& Dish::operator=(const Dish&)’ is implicitly deleted because the default definition would be ill-formed:
class Dish{
^~~~



i cant understand which class cause the problem or what is the problem .
this is part the dish.cpp class.



 #include "../include/Dish.h";
#include <iostream>

Dish::Dish(int d_id, std::string d_name, int d_price, DishType d_type) :
id(d_id), name(d_name)
price(d_price), type(d_type){}

int Dish::getId() const
{
return id;
}

std::string Dish::getName() const {return name;}

int Dish::getPrice() const {return price;}

DishType Dish::getType() const {return type;}


this is the dish.h header file :



#ifndef DISH_H_
#define DISH_H_

#include <string>

enum DishType{
VEG, SPC, BVG, ALC
};

class Dish{
public:
Dish(int d_id, std::string d_name, int d_price, DishType d_type);
int getId() const;
std::string getName() const;
int getPrice() const;
DishType getType() const;
private:
const int id;
const std::string name;
const int price;
const DishType type;
};


#endif









share|improve this question
















im new to c++ and getting the error on my project that represents a resturant:




error: use of deleted function ‘Dish& Dish::operator=(const Dish&)’
*__result = *__first;

In file included from /users/studs/bsc/2019/romid/CLionProjects/rest/src/../include/Customer.h:9:0,
from /users/studs/bsc/2019/romid/CLionProjects/rest/src/../include/Action.h:9,
from /users/studs/bsc/2019/romid/CLionProjects/rest/src/Action.cpp:1:
/users/studs/bsc/2019/romid/CLionProjects/rest/src/../include/Dish.h:19:7: note: ‘Dish& Dish::operator=(const Dish&)’ is implicitly deleted because the default definition would be ill-formed:
class Dish{
^~~~



i cant understand which class cause the problem or what is the problem .
this is part the dish.cpp class.



 #include "../include/Dish.h";
#include <iostream>

Dish::Dish(int d_id, std::string d_name, int d_price, DishType d_type) :
id(d_id), name(d_name)
price(d_price), type(d_type){}

int Dish::getId() const
{
return id;
}

std::string Dish::getName() const {return name;}

int Dish::getPrice() const {return price;}

DishType Dish::getType() const {return type;}


this is the dish.h header file :



#ifndef DISH_H_
#define DISH_H_

#include <string>

enum DishType{
VEG, SPC, BVG, ALC
};

class Dish{
public:
Dish(int d_id, std::string d_name, int d_price, DishType d_type);
int getId() const;
std::string getName() const;
int getPrice() const;
DishType getType() const;
private:
const int id;
const std::string name;
const int price;
const DishType type;
};


#endif






c++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 18:53









Alan Birtles

8,70511033




8,70511033










asked Nov 13 '18 at 18:06









Dor BirendorfDor Birendorf

255




255













  • Are any of your member variables constants or references?

    – Neil Butterworth
    Nov 13 '18 at 18:09











  • all of them are const ( d_name , d_price , d_type, d_id)

    – Dor Birendorf
    Nov 13 '18 at 18:11











  • @DorBirendorf Those are arguments, not members.

    – François Andrieux
    Nov 13 '18 at 18:12











  • Then how are you intending to assign to them? Remove the const qualifier.

    – Neil Butterworth
    Nov 13 '18 at 18:12






  • 1





    no need to approve edits from users with high reputation they are applied automatically, you only need to approve edits from newer users

    – Alan Birtles
    Nov 13 '18 at 18:54



















  • Are any of your member variables constants or references?

    – Neil Butterworth
    Nov 13 '18 at 18:09











  • all of them are const ( d_name , d_price , d_type, d_id)

    – Dor Birendorf
    Nov 13 '18 at 18:11











  • @DorBirendorf Those are arguments, not members.

    – François Andrieux
    Nov 13 '18 at 18:12











  • Then how are you intending to assign to them? Remove the const qualifier.

    – Neil Butterworth
    Nov 13 '18 at 18:12






  • 1





    no need to approve edits from users with high reputation they are applied automatically, you only need to approve edits from newer users

    – Alan Birtles
    Nov 13 '18 at 18:54

















Are any of your member variables constants or references?

– Neil Butterworth
Nov 13 '18 at 18:09





Are any of your member variables constants or references?

– Neil Butterworth
Nov 13 '18 at 18:09













all of them are const ( d_name , d_price , d_type, d_id)

– Dor Birendorf
Nov 13 '18 at 18:11





all of them are const ( d_name , d_price , d_type, d_id)

– Dor Birendorf
Nov 13 '18 at 18:11













@DorBirendorf Those are arguments, not members.

– François Andrieux
Nov 13 '18 at 18:12





@DorBirendorf Those are arguments, not members.

– François Andrieux
Nov 13 '18 at 18:12













Then how are you intending to assign to them? Remove the const qualifier.

– Neil Butterworth
Nov 13 '18 at 18:12





Then how are you intending to assign to them? Remove the const qualifier.

– Neil Butterworth
Nov 13 '18 at 18:12




1




1





no need to approve edits from users with high reputation they are applied automatically, you only need to approve edits from newer users

– Alan Birtles
Nov 13 '18 at 18:54





no need to approve edits from users with high reputation they are applied automatically, you only need to approve edits from newer users

– Alan Birtles
Nov 13 '18 at 18:54












2 Answers
2






active

oldest

votes


















1














The class Dish contains constant members like const int id;. Therefore there will be no usable automatically defined assignment operator, because assigning one Dish to another one would require their ids to be assigned as well, but of course const does not allow changing the value.



Therefore you are not allowed to use assignment of one Dish to another until you provide a user-defined assignment operator.



In particular thinks like



Dish a(...);
Dish b(...);
b = a;


will trigger the error. You are doing something like that somewhere in your code.






share|improve this answer
























  • how can i found where i assign a dish ? its a big project and the error message dont give any info

    – Dor Birendorf
    Nov 13 '18 at 18:47











  • @DorBirendorf All the lines In file included from [...], from [...] etc. in the error message tell you exactly where. The numbers after the file names are the line number and column number. Just look there and if you don't see why these particular lines are responsible, you an add them to your question.

    – user10605163
    Nov 13 '18 at 18:49





















1














As the members of Dish are const the compiler is not able to automatically generate an assignment operator as it can't change the members of an existing object.



You could try to write your own assignment operator but you would run into the same issue. You either need to make the members non-const or stop calling the assignment operator.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287054%2fdeleted-function-build-fail%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The class Dish contains constant members like const int id;. Therefore there will be no usable automatically defined assignment operator, because assigning one Dish to another one would require their ids to be assigned as well, but of course const does not allow changing the value.



    Therefore you are not allowed to use assignment of one Dish to another until you provide a user-defined assignment operator.



    In particular thinks like



    Dish a(...);
    Dish b(...);
    b = a;


    will trigger the error. You are doing something like that somewhere in your code.






    share|improve this answer
























    • how can i found where i assign a dish ? its a big project and the error message dont give any info

      – Dor Birendorf
      Nov 13 '18 at 18:47











    • @DorBirendorf All the lines In file included from [...], from [...] etc. in the error message tell you exactly where. The numbers after the file names are the line number and column number. Just look there and if you don't see why these particular lines are responsible, you an add them to your question.

      – user10605163
      Nov 13 '18 at 18:49


















    1














    The class Dish contains constant members like const int id;. Therefore there will be no usable automatically defined assignment operator, because assigning one Dish to another one would require their ids to be assigned as well, but of course const does not allow changing the value.



    Therefore you are not allowed to use assignment of one Dish to another until you provide a user-defined assignment operator.



    In particular thinks like



    Dish a(...);
    Dish b(...);
    b = a;


    will trigger the error. You are doing something like that somewhere in your code.






    share|improve this answer
























    • how can i found where i assign a dish ? its a big project and the error message dont give any info

      – Dor Birendorf
      Nov 13 '18 at 18:47











    • @DorBirendorf All the lines In file included from [...], from [...] etc. in the error message tell you exactly where. The numbers after the file names are the line number and column number. Just look there and if you don't see why these particular lines are responsible, you an add them to your question.

      – user10605163
      Nov 13 '18 at 18:49
















    1












    1








    1







    The class Dish contains constant members like const int id;. Therefore there will be no usable automatically defined assignment operator, because assigning one Dish to another one would require their ids to be assigned as well, but of course const does not allow changing the value.



    Therefore you are not allowed to use assignment of one Dish to another until you provide a user-defined assignment operator.



    In particular thinks like



    Dish a(...);
    Dish b(...);
    b = a;


    will trigger the error. You are doing something like that somewhere in your code.






    share|improve this answer













    The class Dish contains constant members like const int id;. Therefore there will be no usable automatically defined assignment operator, because assigning one Dish to another one would require their ids to be assigned as well, but of course const does not allow changing the value.



    Therefore you are not allowed to use assignment of one Dish to another until you provide a user-defined assignment operator.



    In particular thinks like



    Dish a(...);
    Dish b(...);
    b = a;


    will trigger the error. You are doing something like that somewhere in your code.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 13 '18 at 18:42









    user10605163user10605163

    2,858624




    2,858624













    • how can i found where i assign a dish ? its a big project and the error message dont give any info

      – Dor Birendorf
      Nov 13 '18 at 18:47











    • @DorBirendorf All the lines In file included from [...], from [...] etc. in the error message tell you exactly where. The numbers after the file names are the line number and column number. Just look there and if you don't see why these particular lines are responsible, you an add them to your question.

      – user10605163
      Nov 13 '18 at 18:49





















    • how can i found where i assign a dish ? its a big project and the error message dont give any info

      – Dor Birendorf
      Nov 13 '18 at 18:47











    • @DorBirendorf All the lines In file included from [...], from [...] etc. in the error message tell you exactly where. The numbers after the file names are the line number and column number. Just look there and if you don't see why these particular lines are responsible, you an add them to your question.

      – user10605163
      Nov 13 '18 at 18:49



















    how can i found where i assign a dish ? its a big project and the error message dont give any info

    – Dor Birendorf
    Nov 13 '18 at 18:47





    how can i found where i assign a dish ? its a big project and the error message dont give any info

    – Dor Birendorf
    Nov 13 '18 at 18:47













    @DorBirendorf All the lines In file included from [...], from [...] etc. in the error message tell you exactly where. The numbers after the file names are the line number and column number. Just look there and if you don't see why these particular lines are responsible, you an add them to your question.

    – user10605163
    Nov 13 '18 at 18:49







    @DorBirendorf All the lines In file included from [...], from [...] etc. in the error message tell you exactly where. The numbers after the file names are the line number and column number. Just look there and if you don't see why these particular lines are responsible, you an add them to your question.

    – user10605163
    Nov 13 '18 at 18:49















    1














    As the members of Dish are const the compiler is not able to automatically generate an assignment operator as it can't change the members of an existing object.



    You could try to write your own assignment operator but you would run into the same issue. You either need to make the members non-const or stop calling the assignment operator.






    share|improve this answer




























      1














      As the members of Dish are const the compiler is not able to automatically generate an assignment operator as it can't change the members of an existing object.



      You could try to write your own assignment operator but you would run into the same issue. You either need to make the members non-const or stop calling the assignment operator.






      share|improve this answer


























        1












        1








        1







        As the members of Dish are const the compiler is not able to automatically generate an assignment operator as it can't change the members of an existing object.



        You could try to write your own assignment operator but you would run into the same issue. You either need to make the members non-const or stop calling the assignment operator.






        share|improve this answer













        As the members of Dish are const the compiler is not able to automatically generate an assignment operator as it can't change the members of an existing object.



        You could try to write your own assignment operator but you would run into the same issue. You either need to make the members non-const or stop calling the assignment operator.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 18:42









        Alan BirtlesAlan Birtles

        8,70511033




        8,70511033






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287054%2fdeleted-function-build-fail%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Coverage of Google Street View

            Full-time equivalent

            Surfing