#include<iostream>
using namespace std;
class Point
{
public:
Point(int A,int B)
{x=A;
y=B;
}
void show()
{
cout<<"the point is :"<<"("<<x<<","<<y<<")"<<endl;
}
protected:
int x,y;
};
class Retangle:public Point
{
public:
Retangle(int A,int B,int L,int W):Point(int A,int B)
{
l=L;
w=W;
}
void show1()
{
cout<<"the Long and Width is :" <<l<<" AND "<<w<<endl;
}
protected:
int l,w;
};
class Cube:public Retangle
{
public:
Cube(int A,int B,int L,int W,int H):Retangle(int A,int B,int L,int W)
{
h=H;
}
void show2()
{
cout<<"the Hight is"<<h<<endl;
}
protected:
int h;
};
int main()
{
Cube T(1,2,3,4,5);
cout<<"the data is:"<<endl;
T.show();
T.show1();
T.show2();
return 0;
}
uj5u.com熱心網友回復:
這種問題編譯器會給出比較明確的提示,不需要來問吧。一篇過下來有兩個明顯的錯誤,錯誤原因一樣:public:
Retangle(int A,int B,int L,int W):Point(int A,int B)
向基類傳遞引數需要直接帶變數,而不是再次宣告原型,應該是:Retangle(int A,int B,int L,int W) : Point(A,B)
同理下面的也是錯誤的:
public:
Cube(int A,int B,int L,int W,int H):Retangle(int A,int B,int L,int W)
應該改成
Cube(int A,int B,int L,int W,int H):Retangle(A,B,L,W)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/81015.html
標籤:基礎類
上一篇:c++決議json檔案
