以下是一个错误的C++程序,请求大神不吝赐教,谢谢(错误和警告已标出)
#include
using namespace std;
const double PI=3.1415926;
class shape
{
public:
virtual ~shape() {}
virtual double getarea() const=0;
virtual void show() const=0;
};
class rectangle:public shape
{
private:
double length;
double width;
public:
rectangle(double l,double w):length(l),width(w){}
double getarea() const{return length*width;}
void show() const{cout<
};
class circle:public
{
private:
double radius;
public:
circle(double r):radius(r){}
double getarea() const{return PI*radius*radius;}
void show() const{cout<};
int main()
{ // error C2059: syntax error : '{'
shape *p;
p=new rectangle(6,5);
p->show();
delete p;
p=new circle(4); //cannot convert from 'class circle *' to 'class shape *'
// Types pointed to are unrelated; conversion requires reinterpret_cast, C-style. cast or function-style. cast
p->show; // warning C4551: function call missing argument list
delete p;
return 0;
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28841997/viewspace-759552/
,如需转载,请注明出处,否则将追究法律责任。