我想编辑一个关于点 圆 柱体的三个类,然后我在编译圆的时候定义了一个r半径,但编译器一直说[Error] invalid use of non-static data member 'Circle::r'是因为非静态成员变量的原因吗,哪位大佬帮我这个菜鸟解读一下,还要就是显示函数问题我也没搞懂哭了
#include<iostream>
using namespace std;
class Point{
friend ostream& operator<<(ostream &output,const Point &c){
cout<<c.x<<","<<c.y<<endl;return output;
}
protected:
int x,y;
public:
Point(int n=0,int i=0){setPoint(n,i);}
setPoint(int p,int q){x=p;y=q;}
};
class Circle:public Point{
protected:
int r;
public:
Circle(int n,int i,int j):Point(n,i){setCircle(j);}
setCircle(int j){r=j;}
int Area()const{return r*r*3.14;}
friend ostream& operator<<(ostream &output,const Circle &c){
cout<<"Center:"<<"["<<c.x<<","<<c.y<<"]"<<endl;
cout<<"The r="<<r<<endl;
cout<<"area:"<<Area();
return output;
}
};
class Cylinder:public Circle{
protected:
int h;
public:
friend ostream& operator<<(ostream &output,const Cylinder &c){
cout<<"Center:"<<"["<<c.x<<","<<c.y<<"]"<<endl;
cout<<"The r="<<r<<endl;
cout<<"area:"<<Area();
cout<<"volume:"<<volume();
return output;
}
Cylinder(int i,int j,int k,int e):Circle(i,j,k){setHigh(e);}
setHigh(int n){h=n;}
int volume()const{return Area()*h;}
};
int main(){
Cylinder obj1(1,2,3,4);
cout<<obj1<<endl;
}