帮忙看看这个C++编程哪错了?谢谢!能改出来就更好了!

来源:百度知道 编辑:UC知道 时间:2024/05/16 23:56:28
#include<iostream>
using namespace std;
class Shape
{
public:
virtual double GetArea()=0;
};

class Rectangle : public Shape
{
public:
Rectangle(double h, double w) : height(h), width(w){}
double GetArea(){ return height * width; }
private:
double height;
double width;
};
class Circle : public Shape
{
public:
Circle(double r):radius(r){}
double GetArea(){ return 3.14159 * radius * radius; }
private:
double radius;
};

class Square : public Rectangle
{
public:
Square(double l) : Rectangle(l, l){}
};
int main()
{
Rectangle rec(2, 2);

Circle cir(1);
Square squ(2);
Shape*my.shape[3]={&rec,&cir,&squ};
for(int i=0;i<3;i++)
{
cout<<my.Shape[i]->GetArea()<<endl;
}
}

改MAIN就好了,主要原因是命名不合法
int main()
{
Rectangle rec(2, 2);

Circle cir(1);
Square squ(2);
Shape *myshape[3]={&rec,&cir,&squ};
for(int i=0;i<3;i++)
{
cout<<myshape[i]->GetArea()<<endl;
}
}

my.shape
你白学了···

你不知道变量名不能有.吗?
另外,注意区分大小写!!!

楼住这里
Shape*my.shape[3]={&rec,&cir,&squ};是什么意思???
Shape是你定义的一个类.类不能和其他数据*的

还有main函数最后应该有个返回值比如return 0;