Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 错误:在C+;中没有用于调用构造函数的匹配函数+;_C++_Oop_Inheritance_Constructor - Fatal编程技术网

C++ 错误:在C+;中没有用于调用构造函数的匹配函数+;

C++ 错误:在C+;中没有用于调用构造函数的匹配函数+;,c++,oop,inheritance,constructor,C++,Oop,Inheritance,Constructor,我正在制作一个小程序,使用构造函数、类、对象和继承来显示所选项目的价格。然而,对于派生类中的两个不同构造函数,我得到了两个错误,我能做些什么来解决这个问题 #include<iostream> using namespace std; class Beverage{ public: int cost_of_water, cost_of_sugar; Beverage(int x, int y){ cost_of_water = x; cost_of_s

我正在制作一个小程序,使用构造函数、类、对象和继承来显示所选项目的价格。然而,对于派生类中的两个不同构造函数,我得到了两个错误,我能做些什么来解决这个问题

#include<iostream>
using namespace std;
class Beverage{
public:
    int cost_of_water, cost_of_sugar;
    Beverage(int x, int y){
    cost_of_water = x;
    cost_of_sugar = y;
    }
    int computeCost(){
    }
    void print(){
    cout<<"The cost of the beverage is: ";
    }
};
class Tea: public Beverage{
public:
    int price_of_tea_leaves;
    Tea(int a){
    price_of_tea_leaves = a;
    }
    int computeCost(){
        int cost = cost_of_sugar + cost_of_water + price_of_tea_leaves;
        return cost;
    }
};
class Coffee: public Beverage{
public:
    int price_of_coffee_powder;
    Coffee(int b){
    price_of_coffee_powder = b;
    }
    int computeCost(){
        int cost = cost_of_sugar + cost_of_water + price_of_coffee_powder;
        return cost;
    }
};
int main(){
    int m,n;
    cout<<"*****Welcome to the cafeteria management system*****";
    cout<<"1 FOR TEA, 2 FOR COFFEE";
    cin>>m;
    if(m = 1){
        Beverage B(10,5);
        Tea T(10);
        B.print();
        T.computeCost();
    }
    else if (m = 2){
       Beverage B(10,5);
       Coffee C(15);
       B.print();
       C.computeCost();
    }
    else{
        cout<<"Thank You!";
    }
}
#包括
使用名称空间std;
高级饮料{
公众:
水的成本,糖的成本;
饮料(国际x、国际y){
水的成本=x;
糖的成本=y;
}
int computeCost(){
}
作废打印(){

cout因此,下面是运行良好的代码:

#include<iostream>
using namespace std;
class Beverage{     //base class
public:                 
    int cost_of_water, cost_of_sugar;
    Beverage(int x, int y){     //base class constructor
    cost_of_water = x;
    cost_of_sugar = y;
    }
    int computeCost(){
    }

};
class Tea: public Beverage{     //derived class
public:
    int price_of_tea_leaves;
    Tea(int a):Beverage(10,5){      //derived class constructor
    price_of_tea_leaves = a;
    }
    int computeCost(){
        int cost = cost_of_sugar + cost_of_water + price_of_tea_leaves;
        return cost;
    }
    void print(){
    cout<<"The cost of the tea is: "<<computeCost();
    }
};
class Coffee: public Beverage{    //derived class
public:
    int price_of_coffee_powder;
    Coffee(int b):Beverage(10,5){       //derived class constructor
    price_of_coffee_powder = b;
    }
    int computeCost(){
        int cost = cost_of_sugar + cost_of_water + price_of_coffee_powder;
        return cost;
    }
    void print(){
    cout<<"The cost of the coffee is: "<<computeCost();
    }
};
int main(){
    int m,n;
    cout<<"*****Welcome to the Cafeteria management system*****"<<endl;;
    cout<<"Input 1 for TEA and 2 for COFFEE: ";
    cin>>m;
    if(m == 1){
        Beverage B(10,5);
        Tea T(10);
        T.print();
    }
    else if (m == 2){
       Beverage B(10,5);
       Coffee C(25);
       C.print();
    }
    else{
        cout<<"ByeBye!";
    }
}
#包括
使用名称空间std;
类{//基类
公众:
水的成本,糖的成本;
饮料(intx,inty){//基类构造函数
水的成本=x;
糖的成本=y;
}
int computeCost(){
}
};
茶类:公共饮料{//衍生类
公众:
茶叶的国际价格;
茶(INTA):饮料(10,5){//派生类构造函数
茶叶价格=a;
}
int computeCost(){
int成本=糖成本+水成本+茶叶价格;
退货成本;
}
作废打印(){
库特