c++类的继承与派生的小问题!!斜杠注释行问什么有了会报错!
#include"stdafx.h"#include<iostream>usingnamespacestd;constdoublePI=3.14159;classshap...
#include "stdafx.h"
#include <iostream>
using namespace std;
const double PI=3.14159;
class shape
{
protected:
int sidevalue1,sidevalue2,high;
public:
void setvalue(int x,int y=0,int h=0)
{
sidevalue1=x;
sidevalue2=y;
high=h;
}
virtual void CalculateArea()=0;
};
class Rectangle:public shape
{
public:
void CalculateArea()
{
cout<<"Area of rectangle:"<<sidevalue1*sidevalue2<<endl;
}
};
class Circle:public shape
{
public:
void CaculateArea()
{
cout<<"Area of circle:"<<PI*sidevalue1*sidevalue2<<endl;
}
};
void main()
{
shape* pointer[2];
//Circle C;
Rectangle r;
//pointer[0]=&C;
//pointer[0]->setvalue(30);
//pointer[0]->CalculateArea();
pointer[1]=&r;
pointer[1]->setvalue(250,180);
pointer[1]->CalculateArea();
} 展开
#include <iostream>
using namespace std;
const double PI=3.14159;
class shape
{
protected:
int sidevalue1,sidevalue2,high;
public:
void setvalue(int x,int y=0,int h=0)
{
sidevalue1=x;
sidevalue2=y;
high=h;
}
virtual void CalculateArea()=0;
};
class Rectangle:public shape
{
public:
void CalculateArea()
{
cout<<"Area of rectangle:"<<sidevalue1*sidevalue2<<endl;
}
};
class Circle:public shape
{
public:
void CaculateArea()
{
cout<<"Area of circle:"<<PI*sidevalue1*sidevalue2<<endl;
}
};
void main()
{
shape* pointer[2];
//Circle C;
Rectangle r;
//pointer[0]=&C;
//pointer[0]->setvalue(30);
//pointer[0]->CalculateArea();
pointer[1]=&r;
pointer[1]->setvalue(250,180);
pointer[1]->CalculateArea();
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询