c++ error C2504:“pulic”: 未定义基类, C2146: 语法错误 : 缺少“,”(在“point”的前面) 怎么改?
#include<iostream>#include<string>#definepi3.1415usingnamespacestd;classpoint{public:...
#include<iostream>
#include<string>
#define pi 3.1415
using namespace std;
class point
{public:
point(float a,float b):x(a),y(b){}
point(){x=0;y=0;}
void setpoint(float a,float b)
{x=a;
y=b;}
float getx() const
{return x;}
float gety() const
{return y;}
friend ostream& operator<<(ostream &,const point &);
protected:
float x,y;
};
ostream& operator<<(ostream &output,const point &p)
{ output<<"point:"<<'['<<p.x<<','<<p.y<<']'<<endl;
return output;}
class circle:pulic point
{
public:
circle(){x=0;y=0;r=0;}
circle(float a,float b,float c):point(a,b),r(c){}
void setradius(float a){r=a;}
float getradius() const {return r;}
double area() const {return r*r*pi;}
friend ostream &operator <<(ostream &output,const circle &p);
protected:
float r;
};
ostream &operator <<(ostream &output, const circle &d)
{output<<"center:"<<'['<<d.x<<','<<d.y<<']'<<endl;
output<<"radius:"<<d.r<<endl;
output<<"area:"<<d.area()<<endl;
return output;}
int main()
{ circle p(1,2,1);
cout<<p;
/*q.setpoint(2,7);
q.setradius(1);
cout<<q.getradius();
cout<<q.area();*/
return 0;} 展开
#include<string>
#define pi 3.1415
using namespace std;
class point
{public:
point(float a,float b):x(a),y(b){}
point(){x=0;y=0;}
void setpoint(float a,float b)
{x=a;
y=b;}
float getx() const
{return x;}
float gety() const
{return y;}
friend ostream& operator<<(ostream &,const point &);
protected:
float x,y;
};
ostream& operator<<(ostream &output,const point &p)
{ output<<"point:"<<'['<<p.x<<','<<p.y<<']'<<endl;
return output;}
class circle:pulic point
{
public:
circle(){x=0;y=0;r=0;}
circle(float a,float b,float c):point(a,b),r(c){}
void setradius(float a){r=a;}
float getradius() const {return r;}
double area() const {return r*r*pi;}
friend ostream &operator <<(ostream &output,const circle &p);
protected:
float r;
};
ostream &operator <<(ostream &output, const circle &d)
{output<<"center:"<<'['<<d.x<<','<<d.y<<']'<<endl;
output<<"radius:"<<d.r<<endl;
output<<"area:"<<d.area()<<endl;
return output;}
int main()
{ circle p(1,2,1);
cout<<p;
/*q.setpoint(2,7);
q.setradius(1);
cout<<q.getradius();
cout<<q.area();*/
return 0;} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询