第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

不知道為什么程序報錯

#include<iostream>

#include<string>

using namespace std;

class Shape{

public:

Shape();

virtual ~Shape();

virtual double calcArea(){

? cout<<"Shape---calcArea()"<<endl;

? return 0;

}

};

Shape::Shape(){

? cout<<"Shape()"<<endl;

}

Shape::~Shape(){

? cout<<"~Shape()"<<endl;

}

class Circle:public Shape{

protected:

double r;

Coordinate *pCenter;

public:

Circle(double _r);

virtual ~Circle();

virtual double calcArea(){

? ?cout<<"Circle---calcArea()"<<endl;

? ?return 3.14*r*r;

}

};

Circle::Circle(double _r){

? ?r=_r;

? ?pCenter=new Coordinate(3,5);

? ?cout<<"Circle"<<endl;

}

Circle::~Circle(){

delete pCenter;

pCenter=NULL;

? ?cout<<"~Circle()"<<endl;

}

class Rect:public Shape{

protected:

? ?double width;

? ?double height;

public:

Rect(double _width,double _height);

virtual ~Rect();

? ? virtual double calcArea(){

? ?cout<<"Rect---calcArea()"<<endl;

? ?return width*height;

}

};

Rect::Rect(double _width,double _height){

? ?width=_width;

? ?height=_height;

? ?cout<<"Rect()"<<endl;

}

Rect::~Rect(){

? cout<<"~Rect()"<<endl;

}

class Coordiante{

private:

int x;

int y;

public:

Coordinate(int _x,int _y);

~Coordinate();

};

Coordinate(int _x,int _y){

? cout<<"Coordinate()"<<endl;

? x=_x;

? y=_y;

}

Coordinate::~Coordinate(){

? cout<<"~Coordinate()"<<endl;

}

int main(){

? Shape *shape1=new Rect(5,6);

? Shape *shape2=new Circle(5);

? shape1->calcArea();

? shape2->calcArea();

? delete shape1;

? shape1=NULL;

? delete shape2;

? shape2=NULL;

? return 0;

}


正在回答

1 回答

  1. Coordinate 要放在前面定義,這樣shape才能調(diào)用

  2. 定義Coordinate的構(gòu)造函數(shù)要寫成Coordinate::Coordinate(int _x, int _y)

  3. 你的class Coordinate打錯了

2 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
C++遠(yuǎn)征之多態(tài)篇
  • 參與學(xué)習(xí)       66225    人
  • 解答問題       329    個

本教程將帶領(lǐng)大家體會面向?qū)ο笕筇匦灾械亩鄳B(tài)特性

進(jìn)入課程

不知道為什么程序報錯

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號