-3
這個代碼中有一個erroe,請幫我解決它。請幫助調試這個C++代碼繼承#constructor_error
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class base
protected:
double area;
string p_name;
int n_side;
void show_out();
base(string,int);
};
class square:public base {
private:
double length,width;
public:
void get_data();
void cal_sarea();
square();
};
class triangle:public base {
private:
double base,height;
public:
void get_data();
void cal_tarea();
triangle();
};
int main() {
square sob1;
triangle tob1;
sob1.get_data();
sob1.cal_sarea();
tob1.get_data();
tob1.cal_tarea();
return 0;
}
void base::show_out() {
cout<<setiosflags(ios::fixed|ios::showpoint) <<setprecision(2)<<area<<endl;
}
void square::get_data() {
cout<<"please enter length"<<endl;
cin>>length;
cout<<"please enter width"<<endl;
cin>>width;
}
void square::cal_sarea() {
area = length * width;
show_out();
}
void triangle::get_data() {
cout<<"please enter base of triangle"<<endl;
cin>>base;
cout<<"please enter height of the triangle"<<endl;
cin>>height;
}
void triangle::cal_tarea() {
area = 0.5 * base * height;
show_out();
}
base::base(string name,int num)
:p_name(name),n_side(num) {}
square::square()
:base("square",4){}
triangle::triangle() // gives a errors here, it says no matching fucntion to call to base::base()
:base("triangle",5) {}
它是編譯器錯誤還是運行時錯誤?如果編譯器錯誤,請將逐字編譯器錯誤文本附加到您的文章中。 – 2015-01-20 21:13:54