#include<iostream>
#define PI 3.14
using namespace std;
class ellipse
{
protected:
float a,b;
public:
ellipse(float x, float y)
{
a=x;
b=y;
}
float area()
{
return (PI*a*b);
}
};
class circle : public ellipse
{
public:
circle(float r)
{
a=r;
b=r;
}
};
main() {
float x,y,r;
cout<<"Enter the two axes of the ellipse (eg. 5 4) : ";
cin>>x>>y;
cout<<"\nEnter the radius of the circle : ";
cin>>r;
ellipse obj(x,y);
cout<<"\nEllipse Area : "<<obj.area();
circle obj1(r);
cout<<"\nCircle Area : "<<obj1.area();
}
: 아래 (시행 착오)와 같이 상속 클래스와 부모의 생성자
friendclass4.cpp: In constructor ‘circle::circle(float)’:
friendclass4.cpp:24:1: error: no matching function for call to ‘ellipse::ellipse()’
friendclass4.cpp:24:1: note: candidates are:
friendclass4.cpp:10:1: note: ellipse::ellipse(float, float)
friendclass4.cpp:10:1: note: candidate expects 2 arguments, 0 provided
friendclass4.cpp:5:7: note: ellipse::ellipse(const ellipse&)
friendclass4.cpp:5:7: note: candidate expects 1 argument, 0 provided
내가 타원의 두 번째 생성자를 추가하고 문제를 해결
ellipse() {
}
하지만이 오류를 추가하기 전에 오류가 발생한 이유를 모르겠습니다. 아무도 나에게 이것을 설명 할 수 있습니까?
서식을 수정하십시오. – 0x499602D2
원 - 타원 문제에 대해 들어 보셨습니까? http://en.wikipedia.org/wiki/Circle-ellipse_problem –