No suitable default constructor available

Asked 2 years ago, Updated 2 years ago, 92 views

No suitable default constructor available Error appears

This is one of the header files of the fruit-buying program

There's only one constructor error stuck here.

class FruitSeller
{
private:
    const int APPLE_PRICE;
    const int ORANGE_PRICE;
    int numOfApples;
    int numOfOranges;
    int myMoney;


public:
    FruitSeller(int aprice, int oprice, int anum, int onum, int money)
        : : APPLE_PRICE(aprice), ORANGE_PRICE(oprice), numOfApples(anum), numOfOranges(onum), myMoney(money)
    {

    }
    void InitMembers(int aprice, int oprice, int anum, int onum, int money);
    int SaleApples(int money);
    int SaleOranges(int money);
    void ShowSalesResult();
};

c++ class constructor

2022-09-20 10:54

1 Answers

Please add the default constructor under public as below.

FruitSeller()  : APPLE_PRICE(0), ORANGE_PRICE(0), numOfApples(0), numOfOranges(0), myMoney(0)
{
}


2022-09-20 10:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.