도와주세요 에러를 못고치겠어요 ㅠ_ㅠ
Addictive
질문 제목 : 과제를 하다가 막혀서 올려봅니다.
-도형(shape) class를 정의하고, 이를 상속받아 사각형(rectangle), 원(circle) class를 정의하고, 각각의 특성에 맞는 draw()라는 함수를 정의해 본다.-각 클래스마다 소스파일과 헤더파일을 각각(!) 만든다.
질문은 소스파일과 헤더파일을 각각만 들었습니다만 에러가 뜨는데 잡을 수가 없군요;; 사실 초보로 머가 잘못된지 모르겠는데요.클레스 변환이 안된다고 뜨더라고요 머가 잘못된것인지 좀 알려주세요. 메인은 이상이 없습니다. 클레스부분이 잘못된거 같은데 좀 봐주세요-_-;
질문 내용 :
main.cpp
#include cstdio
#include myshape.h
#include myrect.h
#include mycircle.h
int main()
{
myshape* shapes[5] = {null} ;
shapes[0] = new mycircle( 100, 100, 50);
shapes[1] = new myrect( 300, 300, 100, 100);
shapes[2] = new myrect( 200, 100, 50, 150);
shapes[3] = new mycircle(100, 300, 150);
shapes[4] = new myrect( 200, 200, 200, 200);
for (int i = 0; i 5; ++i)
shapes[i]-draw();
for (int i = 0; i 5; ++i)
{
delete shapes[i];
shapes[i] = null;
}}
mycircle.cpp
#include cstdio
#include mycircle.h
void mycircle::draw() const{
printf([circle] position = ( %.f, %.f ), radius = ( %.f ), _x, _y,_radius);
}
myrect.cpp
#include cstdio
#include myrect.h
void myrect::draw() const{
printf([rectangle] position = ( %.f, %.f ), size = ( %.f, %.f ), _x, _y,_width, _height);
}
myshape.cpp
#include cstdio
#include myshape.h
void myshape::draw(){
printf([rintf([shape] position = ( %.f, %.f ), _x, _y);
}
mycircle.h
#include myshape.h
class mycircle : public myshape{//상속을 합니다
public:
float _radius;
mycircle(float x, float y,float r);
void draw() const;
};
mycircle::mycircle(float r):myshape(float x, float y){
_x = x;
_y = y;
_radius = r;
}
myrect.h
#include myshape.h
class myrect : public myshape{//상속을 합니다
public:
float _width,_height;
myrect(float x, float y,float w, float h);
void draw() const;
};
myrect::myrect(float w, float h)::myshape(float x, float y){
_x = x;
_y = y;
_width = w;
_height = h;
}
myshape.h
class myshape{
public:
float _x,_y;
myshape(float x, float y);
virtual void draw() ;
};
myshape::myshape(float x, float y){
_x = x;
_y = y;
}
결과가 이렇게 나와야 하는데 계속 에러내요-_ㅠ;; 머가 틀린건지 알려주세요
컴파일하면 변환할수 없는 클래스라고 나오네요....머가 잘못된건지.
빠른 답변을 원해요..그리고 틀린곳이 머가 잘못된것인지 자세히 설명좀 부탁드립니다.
-
맑은
빠른 답변을 원하시고 틀린곳이 뭐가 잘못된 것인지 자세히 설명해드릴꼐요
돈을 주세요